use of com.github.moko256.twitlatte.model.impl.StatusActionModelImpl 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);
}
}
Aggregations