anotherim/src/main/java/eu/siacs/conversations/ui/MediaBrowserActivity.java

77 lines
2.6 KiB
Java
Raw Normal View History

2018-09-15 19:10:17 +00:00
package eu.siacs.conversations.ui;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
2021-01-23 08:25:34 +00:00
import androidx.databinding.DataBindingUtil;
2018-09-15 19:10:17 +00:00
import java.util.List;
import eu.siacs.conversations.R;
2021-01-23 08:25:34 +00:00
import eu.siacs.conversations.databinding.ActivityMediaBrowserBinding;
2018-09-15 19:10:17 +00:00
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.ui.adapter.MediaAdapter;
import eu.siacs.conversations.ui.interfaces.OnMediaLoaded;
import eu.siacs.conversations.ui.util.Attachment;
import eu.siacs.conversations.ui.util.GridManager;
2020-05-15 15:06:16 +00:00
import eu.siacs.conversations.xmpp.Jid;
2018-09-15 19:10:17 +00:00
public class MediaBrowserActivity extends XmppActivity implements OnMediaLoaded {
private ActivityMediaBrowserBinding binding;
private MediaAdapter mMediaAdapter;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.binding = DataBindingUtil.setContentView(this,R.layout.activity_media_browser);
2021-01-23 08:25:34 +00:00
setSupportActionBar(binding.toolbar);
2018-09-15 19:10:17 +00:00
configureActionBar(getSupportActionBar());
mMediaAdapter = new MediaAdapter(this, R.dimen.media_size);
this.binding.media.setAdapter(mMediaAdapter);
GridManager.setupLayoutManager(this, this.binding.media, R.dimen.browser_media_size);
}
@Override
protected void refreshUiReal() {
}
@Override
void onBackendConnected() {
Intent intent = getIntent();
String account = intent == null ? null : intent.getStringExtra("account");
String jid = intent == null ? null : intent.getStringExtra("jid");
if (account != null && jid != null) {
2020-05-18 09:48:24 +00:00
xmppConnectionService.getAttachments(account, Jid.ofEscaped(jid), 0, this);
2018-09-15 19:10:17 +00:00
}
}
public static void launch(Context context, Contact contact) {
launch(context, contact.getAccount(), contact.getJid().asBareJid().toEscapedString());
}
public static void launch(Context context, Conversation conversation) {
launch(context, conversation.getAccount(), conversation.getJid().asBareJid().toEscapedString());
}
private static void launch(Context context, Account account, String jid) {
final Intent intent = new Intent(context, MediaBrowserActivity.class);
intent.putExtra("account",account.getUuid());
intent.putExtra("jid",jid);
context.startActivity(intent);
}
@Override
public void onMediaLoaded(List<Attachment> attachments) {
runOnUiThread(()->{
mMediaAdapter.setAttachments(attachments);
});
}
}