Search in sources :

Example 1 with StatusActionModelImpl

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);
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) StatusActionModel(com.github.moko256.twitlatte.model.base.StatusActionModel) Intent(android.content.Intent) LinkMovementMethod(android.text.method.LinkMovementMethod) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AppCustomTabsKt(com.github.moko256.twitlatte.intent.AppCustomTabsKt) MenuItem(android.view.MenuItem) ClipData(android.content.ClipData) ActionBar(androidx.appcompat.app.ActionBar) SuppressLint(android.annotation.SuppressLint) ActivityOptionsCompat(androidx.core.app.ActivityOptionsCompat) RequestManager(com.bumptech.glide.RequestManager) TwitterStringUtils(com.github.moko256.twitlatte.text.TwitterStringUtils) Toast(android.widget.Toast) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Menu(android.view.Menu) ClipboardManager(android.content.ClipboardManager) View(android.view.View) Button(android.widget.Button) VISIBLE(android.view.View.VISIBLE) StatusActionModelImpl(com.github.moko256.twitlatte.model.impl.StatusActionModelImpl) DateFormat(java.text.DateFormat) Post(com.github.moko256.latte.client.base.entity.Post) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) Client(com.github.moko256.twitlatte.entity.Client) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Unit(kotlin.Unit) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) GONE(android.view.View.GONE) StatusActionModelImpl(com.github.moko256.twitlatte.model.impl.StatusActionModelImpl) Post(com.github.moko256.latte.client.base.entity.Post) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ActionBar(androidx.appcompat.app.ActionBar) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 LinkMovementMethod (android.text.method.LinkMovementMethod)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 GONE (android.view.View.GONE)1 VISIBLE (android.view.View.VISIBLE)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 ActionBar (androidx.appcompat.app.ActionBar)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 ActivityOptionsCompat (androidx.core.app.ActivityOptionsCompat)1 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 Glide (com.bumptech.glide.Glide)1