diff options
Diffstat (limited to 'src/main')
9 files changed, 115 insertions, 2 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index f9a50b2a1..bfdb2ec3d 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -275,6 +275,10 @@ android:theme="@style/Base.Theme.AppCompat" /> <activity android:name=".ui.MemorizingActivity" /> + <activity + android:name=".ui.MediaBrowserActivity" + android:label="@string/media_browser" /> + <service android:name=".services.ExportLogsService" /> <service android:name=".services.ContactChooserTargetService" diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 54d99ec43..365f8fa87 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -788,10 +788,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { }; } - public List<FilePath> getRelativeFilePaths(Account account, Jid jid, int limit) { + public List<FilePath> 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<FilePath> filesPaths = new ArrayList<>(); while (cursor.moveToNext()) { diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index cd35198dc..1b1ad1829 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -2687,6 +2687,10 @@ public class XmppConnectionService extends Service { } 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 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/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java index fd7c66c18..72168ab89 100644 --- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java @@ -523,6 +523,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/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index d488419d2..4e1e414fa 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -669,6 +669,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/de/pixart/messenger/ui/MediaBrowserActivity.java b/src/main/java/de/pixart/messenger/ui/MediaBrowserActivity.java new file mode 100644 index 000000000..4b32b42ab --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/MediaBrowserActivity.java @@ -0,0 +1,77 @@ +package de.pixart.messenger.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 de.pixart.messenger.R; +import de.pixart.messenger.databinding.ActivityMediaBrowserBinding; +import de.pixart.messenger.entities.Account; +import de.pixart.messenger.entities.Contact; +import de.pixart.messenger.entities.Conversation; +import de.pixart.messenger.ui.adapter.MediaAdapter; +import de.pixart.messenger.ui.interfaces.OnMediaLoaded; +import de.pixart.messenger.ui.util.Attachment; +import de.pixart.messenger.ui.util.GridManager; +import rocks.xmpp.addr.Jid; + + +public class MediaBrowserActivity extends XmppActivity implements OnMediaLoaded { + + private ActivityMediaBrowserBinding binding; + + private MediaAdapter mMediaAdapter; + + 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 + 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); + } + } + + @Override + public void onMediaLoaded(List<Attachment> attachments) { + runOnUiThread(() -> { + mMediaAdapter.setAttachments(attachments); + }); + } +}
\ No newline at end of file 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..149f2c164 --- /dev/null +++ b/src/main/res/layout/activity_media_browser.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<layout xmlns:android="http://schemas.android.com/apk/res/android"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="?attr/color_background_primary" + android:orientation="vertical"> + + <include + android:id="@+id/toolbar" + layout="@layout/toolbar" /> + + <android.support.v7.widget.RecyclerView + android:id="@+id/media" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:clipToPadding="false" + android:orientation="horizontal" + android:padding="2dp" + android:scrollbars="vertical" /> + + </LinearLayout> +</layout>
\ No newline at end of file diff --git a/src/main/res/values/dimens.xml b/src/main/res/values/dimens.xml index 055c492d3..e1c604d3c 100644 --- a/src/main/res/values/dimens.xml +++ b/src/main/res/values/dimens.xml @@ -12,6 +12,7 @@ <dimen name="media_preview_size">80dp</dimen> <dimen name="media_size">64dp</dimen> + <dimen name="browser_media_size">96dp</dimen> <dimen name="toolbar_elevation">4dp</dimen> <dimen name="publish_avatar_top_margin">8dp</dimen> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2287687fb..05a5678a7 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -825,4 +825,5 @@ <string name="app_update_channel_name">App update</string> <string name="action_group_details">Group details</string> <string name="show_media">Show media</string> + <string name="media_browser">Media browser</string> </resources> |