Created
October 7, 2014 15:23
-
-
Save DavidCulpepper/ca9729ea550090c64faa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Manifest attributes | |
@NoTitle | |
@Fullscreen | |
public class BookmarksToClipboardActivity extends Activity { | |
BookmarkAdapter adapter; | |
@InjectView(R.id.bookmarkList) | |
ListView bookmarkList; | |
@InjectView(R.id.search) | |
EditText search; | |
@Inject | |
BookmarkApplication application; | |
@Inject | |
BookmarkClient restClient; | |
@Inject @FadeIn Animation fadeIn; | |
@Inject ClipboardManager clipboardManager; | |
public void onCreate(Bundle state) { | |
super.onCreate(state); | |
setContentView(R.layout.bookmarks); | |
ButterKnife.inject(this); | |
BookmarkApplication.inject(this); | |
initBookmarkList(); | |
} | |
void initBookmarkList() { | |
adapter = new BookmarkAdapter(this); | |
bookmarkList.setAdapter(adapter); | |
} | |
@OnClick({R.id.updateBookmarksButton1, R.id.updateBookmarksButton2}) | |
void updateBookmarksClicked() { | |
searchAsync(search.getText().toString(), application.getUserId()); | |
} | |
void searchAsync(String searchString, String userId) { | |
restClient.getBookmarks(searchString, userId) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe((b) -> updateBookmarks(b)); | |
} | |
void updateBookmarks(Bookmarks bookmarks) { | |
adapter.updateBookmarks(bookmarks); | |
bookmarkList.startAnimation(fadeIn); | |
} | |
@OnItemClick(R.id.bookmarkList) | |
void bookmarkListItemClicked(Bookmark selectedBookmark) { | |
clipboardManager.setText(selectedBookmark.getUrl()); | |
} | |
} | |
// Retrofit | |
@Rest("http://www.bookmarks.com") | |
public interface BookmarkClient { | |
@Get("/bookmarks/{userId}?search={search}") | |
Bookmarks getBookmarks(String search, String userId); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment