use of com.github.moko256.twitlatte.model.base.StatusActionModel 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.twitlatte.model.base.StatusActionModel in project twicalico by moko256.
the class StatusesAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
if (viewHolder instanceof MoreLoadViewHolder) {
ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) layoutParams).setFullSpan(true);
}
((MoreLoadViewHolder) viewHolder).setIsLoading(false);
viewHolder.itemView.setOnClickListener(v -> {
((MoreLoadViewHolder) viewHolder).setIsLoading(true);
onLoadMoreClick.onClick(i);
});
} else {
Post post = client.getPostCache().getPost(data.get(i));
if (post != null) {
if (viewHolder instanceof StatusViewHolder) {
((StatusViewHolder) viewHolder).setStatus(client, statusActionModel, glideRequests, post.getRepeatedUser(), post.getRepeat(), post.getUser(), post.getStatus(), post.getQuotedRepeatingUser(), post.getQuotedRepeatingStatus());
} else if (viewHolder instanceof ImagesOnlyTweetViewHolder) {
((ImagesOnlyTweetViewHolder) viewHolder).setStatus(client, post.getStatus(), glideRequests);
}
}
}
}
Aggregations