use of com.github.moko256.latte.client.base.entity.Status in project twicalico by moko256.
the class BaseTweetListFragment method onInitializeList.
@Override
protected void onInitializeList() {
setRefreshing(true);
subscription.add(getResponseSingle(new Paging(1, 20)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
List<Long> ids = Observable.from(result).map(Status::getId).toList().toSingle().toBlocking().value();
list.addAll(ids);
statusIdsDatabase.addIds(ids);
adapter.notifyDataSetChanged();
setRefreshing(false);
}, e -> {
e.printStackTrace();
Snackbar.make(getSnackBarParentContainer(), TwitterStringUtils.convertErrorToText(e), Snackbar.LENGTH_INDEFINITE).setAction(R.string.retry, v -> {
setRefreshing(true);
onInitializeList();
}).show();
setRefreshing(false);
}));
}
use of com.github.moko256.latte.client.base.entity.Status in project twicalico by moko256.
the class BaseTweetListFragment method onUpdateList.
@Override
protected void onUpdateList() {
subscription.add(getResponseSingle(new Paging(list.get(list.size() >= 2 ? 1 : 0)).count(GlobalApplication.statusLimit)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
if (result.size() > 0) {
List<Long> ids = Observable.from(result).map(Status::getId).toList().toSingle().toBlocking().value();
if (ids.get(ids.size() - 1).equals(list.get(0))) {
ids.remove(ids.size() - 1);
} else {
ids.add(-1L);
}
if (ids.size() > 0) {
list.addAll(0, ids);
statusIdsDatabase.insertIds(0, ids);
adapter.notifyItemRangeInserted(0, ids.size());
TypedValue value = new TypedValue();
Toast t = Toast.makeText(getContext(), R.string.new_post, Toast.LENGTH_SHORT);
t.setGravity(Gravity.TOP | Gravity.CENTER, 0, getContext().getTheme().resolveAttribute(R.attr.actionBarSize, value, true) ? TypedValue.complexToDimensionPixelOffset(value.data, getResources().getDisplayMetrics()) : 0);
t.show();
}
}
setRefreshing(false);
}, e -> {
e.printStackTrace();
Snackbar.make(getSnackBarParentContainer(), TwitterStringUtils.convertErrorToText(e), Snackbar.LENGTH_INDEFINITE).setAction(R.string.retry, v -> {
setRefreshing(true);
onUpdateList();
}).show();
setRefreshing(false);
}));
}
use of com.github.moko256.latte.client.base.entity.Status in project twicalico by moko256.
the class ShowTweetActivity method onCreate.
@SuppressLint("WrongConstant")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_tweet);
statusId = getIntent().getLongExtra("statusId", -1);
client = GlobalApplicationKt.getClient(this);
requestManager = Glide.with(this);
statusActionModel = new StatusActionModelImpl(client.getApiClient(), client.getPostCache());
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_back_white_24dp);
tweetIsReply = findViewById(R.id.tweet_show_is_reply_text);
statusViewBinder = new StatusViewBinder(findViewById(R.id.tweet_show_tweet));
timestampText = findViewById(R.id.tweet_show_timestamp);
viaText = findViewById(R.id.tweet_show_via);
replyFab = findViewById(R.id.tweet_show_fab);
SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.tweet_show_swipe_refresh);
swipeRefreshLayout.setColorSchemeResources(R.color.color_primary);
swipeRefreshLayout.setOnRefreshListener(() -> statusActionModel.updateStatus(statusId));
disposables.addAll(statusActionModel.getStatusObservable().subscribe(id -> {
Post post = client.getPostCache().getPost(statusId);
if (post != null) {
if (!isVisible) {
isVisible = true;
swipeRefreshLayout.getChildAt(0).setVisibility(VISIBLE);
}
updateView(post);
}
swipeRefreshLayout.setRefreshing(false);
}), statusActionModel.getDidActionObservable().subscribe(it -> Toast.makeText(this, TwitterStringUtils.getDidActionStringRes(client.getAccessToken().getClientType(), it), Toast.LENGTH_SHORT).show()), statusActionModel.getErrorObservable().subscribe(error -> {
error.printStackTrace();
Toast.makeText(this, error.getMessage(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
if (client.getPostCache().getPost(statusId) == null) {
finish();
}
}));
Post status = client.getPostCache().getPost(statusId);
if (status != null) {
updateView(status);
} else {
swipeRefreshLayout.setRefreshing(true);
isVisible = false;
swipeRefreshLayout.getChildAt(0).setVisibility(GONE);
statusActionModel.updateStatus(statusId);
}
}
use of com.github.moko256.latte.client.base.entity.Status in project twicalico by moko256.
the class StatusesAdapter method getItemViewType.
@Override
public int getItemViewType(int position) {
if (data.get(position) == -1L) {
return R.layout.layout_list_load_more_text;
}
Post post = client.getPostCache().getPost(data.get(position));
if (!(post != null && post.getStatus() != null)) {
return R.layout.layout_list_load_more_text;
}
Status item = post.getStatus();
User user = post.getUser();
if ((conf.getBoolean(KEY_IS_PATTERN_TWEET_MUTE, false) && conf.getPattern(KEY_TWEET_MUTE_PATTERN).matcher(item.getText()).find()) || (conf.getBoolean(KEY_IS_PATTERN_USER_SCREEN_NAME_MUTE, false) && conf.getPattern(KEY_USER_SCREEN_NAME_MUTE_PATTERN).matcher(user.getScreenName()).find()) || (conf.getBoolean(KEY_IS_PATTERN_USER_NAME_MUTE, false) && conf.getPattern(KEY_USER_NAME_MUTE_PATTERN).matcher(user.getName()).find()) || (conf.getBoolean(KEY_IS_PATTERN_TWEET_SOURCE_MUTE, false) && conf.getPattern(KEY_TWEET_SOURCE_MUTE_PATTERN).matcher((item.getSourceName() != null) ? item.getSourceName() : "").find())) {
return R.layout.layout_list_muted_text;
} else if (shouldShowMediaOnly || (conf.getBoolean(KEY_IS_PATTERN_TWEET_MUTE_SHOW_ONLY_IMAGE, false) && item.getMedias() != null && conf.getPattern(KEY_TWEET_MUTE_SHOW_ONLY_IMAGE_PATTERN).matcher(item.getText()).find())) {
return R.layout.layout_list_tweet_only_image;
} else {
return R.layout.layout_post_card;
}
}
use of com.github.moko256.latte.client.base.entity.Status in project twicalico by moko256.
the class CachedStatusesSQLiteOpenHelperTest method addCacheTest.
private void addCacheTest() {
helper.addCachedStatus(generateStatus(TEST_DUMMY_STATUS_ID_1, TEST_DUMMY_STATUS_TEXT_0), false);
StatusObject addedStatusResult = helper.getCachedStatus(TEST_DUMMY_STATUS_ID_1);
assertEquals(((Status) addedStatusResult).getText(), TEST_DUMMY_STATUS_TEXT_0);
}
Aggregations