From 7a0c53aa71c7f405d5bd9b838a90f69ead9a021a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 15 Sep 2018 21:10:17 +0200 Subject: [PATCH] introduce media browser activity --- src/main/AndroidManifest.xml | 3 + .../persistance/DatabaseBackend.java | 4 +- .../services/XmppConnectionService.java | 6 +- .../ui/ConferenceDetailsActivity.java | 1 + .../ui/ContactDetailsActivity.java | 7 +- .../ui/MediaBrowserActivity.java | 77 +++++++++++++++++++ .../res/layout/activity_media_browser.xml | 24 ++++++ src/main/res/values/dimens.xml | 1 + src/main/res/values/strings.xml | 1 + 9 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/ui/MediaBrowserActivity.java create mode 100644 src/main/res/layout/activity_media_browser.xml diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 9bfdc6e0b..6f950be3c 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -235,6 +235,9 @@ android:theme="@style/Base.Theme.AppCompat"/> + + getRelativeFilePaths(Account account, Jid jid, int limit) { + public List getRelativeFilePaths(String account, Jid jid, int limit) { SQLiteDatabase db = this.getReadableDatabase(); final String SQL = "select uuid,relativeFilePath from messages where type in (1,2) and conversationUuid=(select uuid from conversations where accountUuid=? and (contactJid=? or contactJid like ?)) order by timeSent desc"; - final String[] args = {account.getUuid(), jid.asBareJid().toEscapedString(), jid.asBareJid().toEscapedString()+"/%"}; + final String[] args = {account, jid.toEscapedString(), jid.toEscapedString()+"/%"}; Cursor cursor = db.rawQuery(SQL+(limit > 0 ? " limit "+String.valueOf(limit) : ""), args); List filesPaths = new ArrayList<>(); while(cursor.moveToNext()) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 61a67dcde..fc43adb5f 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2425,8 +2425,12 @@ public class XmppConnectionService extends Service { getAttachments(conversation.getAccount(), conversation.getJid().asBareJid(), limit, onMediaLoaded); } + public void getAttachments(final Account account, final Jid jid, final int limit, final OnMediaLoaded onMediaLoaded) { + getAttachments(account.getUuid(),jid.asBareJid(),limit, onMediaLoaded); + } - public void getAttachments(final Account account, final Jid jid, final int limit, final OnMediaLoaded onMediaLoaded) { + + public void getAttachments(final String account, final Jid jid, final int limit, final OnMediaLoaded onMediaLoaded) { new Thread(() -> onMediaLoaded.onMediaLoaded(fileBackend.convertToAttachments(databaseBackend.getRelativeFilePaths(account, jid, limit)))).start(); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 230414adb..a5339b9ba 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -488,6 +488,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers if (this.mConversation != null) { final int limit = GridManager.getCurrentColumnCount(this.binding.media); xmppConnectionService.getAttachments(this.mConversation, limit, this); + this.binding.showMedia.setOnClickListener((v)->MediaBrowserActivity.launch(this,mConversation)); updateView(); } } diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 98c9c4ca9..edfed9f05 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -1,7 +1,6 @@ package eu.siacs.conversations.ui; import android.content.ActivityNotFoundException; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; @@ -12,18 +11,13 @@ import android.preference.PreferenceManager; import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Intents; -import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.ViewTreeObserver; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.TextView; @@ -488,6 +482,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp final int limit = GridManager.getCurrentColumnCount(this.binding.media); xmppConnectionService.getAttachments(account, contact.getJid().asBareJid(), limit, this); + this.binding.showMedia.setOnClickListener((v)->MediaBrowserActivity.launch(this,contact)); populateView(); } } diff --git a/src/main/java/eu/siacs/conversations/ui/MediaBrowserActivity.java b/src/main/java/eu/siacs/conversations/ui/MediaBrowserActivity.java new file mode 100644 index 000000000..02855216f --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/MediaBrowserActivity.java @@ -0,0 +1,77 @@ +package eu.siacs.conversations.ui; + +import android.content.Context; +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.v7.widget.Toolbar; + +import java.util.List; + +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.entities.Conversation; + +import eu.siacs.conversations.databinding.ActivityMediaBrowserBinding; +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; +import rocks.xmpp.addr.Jid; + +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); + setSupportActionBar((Toolbar) binding.toolbar); + 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) { + xmppConnectionService.getAttachments(account, Jid.of(jid), 0, this); + } + } + + 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 attachments) { + runOnUiThread(()->{ + mMediaAdapter.setAttachments(attachments); + }); + } +} diff --git a/src/main/res/layout/activity_media_browser.xml b/src/main/res/layout/activity_media_browser.xml new file mode 100644 index 000000000..4a54e5fd4 --- /dev/null +++ b/src/main/res/layout/activity_media_browser.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/values/dimens.xml b/src/main/res/values/dimens.xml index b648c4408..dac74232d 100644 --- a/src/main/res/values/dimens.xml +++ b/src/main/res/values/dimens.xml @@ -13,6 +13,7 @@ 80dp 64dp + 96dp 4dp 8dp diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 27e3b035b..a15f6b579 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -735,4 +735,5 @@ Importance, Sound, Vibrate Video compression Show media + Media browser