diff --git a/res/layout/profile_document_item.xml b/res/layout/profile_document_item.xml
index 38e1c60f7..c2207ca97 100644
--- a/res/layout/profile_document_item.xml
+++ b/res/layout/profile_document_item.xml
@@ -26,5 +26,18 @@
android:textColor="?attr/profile_document_foreground"
android:paddingTop="20dp"
tools:text="Jun 1"/>
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/profile_gallery_item_header.xml b/res/layout/profile_gallery_item_header.xml
deleted file mode 100644
index b0a2b6148..000000000
--- a/res/layout/profile_gallery_item_header.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout/profile_document_item_header.xml b/res/layout/profile_item_header.xml
similarity index 100%
rename from res/layout/profile_document_item_header.xml
rename to res/layout/profile_item_header.xml
diff --git a/src/org/thoughtcrime/securesms/ProfileActivity.java b/src/org/thoughtcrime/securesms/ProfileActivity.java
index 82c65941d..53ce1b50d 100644
--- a/src/org/thoughtcrime/securesms/ProfileActivity.java
+++ b/src/org/thoughtcrime/securesms/ProfileActivity.java
@@ -196,7 +196,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity {
default:
fragment = new ProfileDocumentsFragment();
- args.putString(ProfileDocumentsFragment.ADDRESS_EXTRA, getRecipient().getAddress().serialize());
+ args.putInt(ProfileGalleryFragment.CHAT_ID_EXTRA, dcChat==null? -1 : chatId);
args.putSerializable(ProfileDocumentsFragment.LOCALE_EXTRA, dynamicLanguage.getCurrentLocale());
break;
}
diff --git a/src/org/thoughtcrime/securesms/ProfileDocumentsAdapter.java b/src/org/thoughtcrime/securesms/ProfileDocumentsAdapter.java
index adbeed812..277963f6a 100644
--- a/src/org/thoughtcrime/securesms/ProfileDocumentsAdapter.java
+++ b/src/org/thoughtcrime/securesms/ProfileDocumentsAdapter.java
@@ -1,34 +1,137 @@
package org.thoughtcrime.securesms;
-
import android.content.Context;
-import android.content.Intent;
-import android.database.Cursor;
import android.support.annotation.NonNull;
-import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
-import org.thoughtcrime.securesms.ProfileDocumentsAdapter.HeaderViewHolder;
-import org.thoughtcrime.securesms.ProfileDocumentsAdapter.ViewHolder;
-import org.thoughtcrime.securesms.components.DocumentView;
-import org.thoughtcrime.securesms.connect.ApplicationDcContext;
-import org.thoughtcrime.securesms.connect.DcHelper;
-import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter;
-import org.thoughtcrime.securesms.database.MediaDatabase;
-import org.thoughtcrime.securesms.mms.DocumentSlide;
+import com.b44t.messenger.DcMsg;
+import com.codewaves.stickyheadergrid.StickyHeaderGridAdapter;
+
+import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader.BucketedThreadMedia;
+import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.mms.Slide;
-import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.MediaUtil;
-import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
-import org.thoughtcrime.securesms.util.Util;
-import java.util.Calendar;
-import java.util.Date;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Locale;
+import java.util.Set;
+class ProfileDocumentsAdapter extends StickyHeaderGridAdapter {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = ProfileDocumentsAdapter.class.getSimpleName();
+
+ private final Context context;
+ private final GlideRequests glideRequests;
+ private final Locale locale;
+ private final ItemClickListener itemClickListener;
+ private final Set selected;
+
+ private BucketedThreadMedia media;
+
+ private static class ViewHolder extends StickyHeaderGridAdapter.ItemViewHolder {
+ View selectedIndicator;
+
+ ViewHolder(View v) {
+ super(v);
+ selectedIndicator = v.findViewById(R.id.selected_indicator);
+ }
+ }
+
+ private static class HeaderHolder extends StickyHeaderGridAdapter.HeaderViewHolder {
+ TextView textView;
+
+ HeaderHolder(View itemView) {
+ super(itemView);
+ textView = itemView.findViewById(R.id.text);
+ }
+ }
+
+ ProfileDocumentsAdapter(@NonNull Context context,
+ @NonNull GlideRequests glideRequests,
+ BucketedThreadMedia media,
+ Locale locale,
+ ItemClickListener clickListener)
+ {
+ this.context = context;
+ this.glideRequests = glideRequests;
+ this.locale = locale;
+ this.media = media;
+ this.itemClickListener = clickListener;
+ this.selected = new HashSet<>();
+ }
+
+ public void setMedia(BucketedThreadMedia media) {
+ this.media = media;
+ }
+
+ @Override
+ public StickyHeaderGridAdapter.HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent, int headerType) {
+ return new HeaderHolder(LayoutInflater.from(context).inflate(R.layout.profile_item_header, parent, false));
+ }
+
+ @Override
+ public ItemViewHolder onCreateItemViewHolder(ViewGroup parent, int itemType) {
+ return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.profile_document_item, parent, false));
+ }
+
+ @Override
+ public void onBindHeaderViewHolder(StickyHeaderGridAdapter.HeaderViewHolder viewHolder, int section) {
+ ((HeaderHolder)viewHolder).textView.setText(media.getName(section, locale));
+ }
+
+ @Override
+ public void onBindItemViewHolder(ItemViewHolder viewHolder, int section, int offset) {
+ DcMsg mediaRecord = media.get(section, offset);
+ View selectedIndicator = ((ViewHolder)viewHolder).selectedIndicator;
+ Slide slide = MediaUtil.getSlideForMsg(context, mediaRecord);
+
+
+ selectedIndicator.setVisibility(selected.contains(mediaRecord) ? View.VISIBLE : View.GONE);
+ }
+
+ @Override
+ public int getSectionCount() {
+ return media.getSectionCount();
+ }
+
+ @Override
+ public int getSectionItemCount(int section) {
+ return media.getSectionItemCount(section);
+ }
+
+ public void toggleSelection(@NonNull DcMsg mediaRecord) {
+ if (!selected.remove(mediaRecord)) {
+ selected.add(mediaRecord);
+ }
+ notifyDataSetChanged();
+ }
+
+ public int getSelectedMediaCount() {
+ return selected.size();
+ }
+
+ @NonNull
+ public Collection getSelectedMedia() {
+ return new HashSet<>(selected);
+ }
+
+ public void clearSelection() {
+ selected.clear();
+ notifyDataSetChanged();
+ }
+
+ interface ItemClickListener {
+ void onMediaClicked(@NonNull DcMsg mediaRecord);
+ void onMediaLongClicked(DcMsg mediaRecord);
+ }
+}
+
+/*
public class ProfileDocumentsAdapter extends CursorRecyclerViewAdapter implements StickyHeaderDecoration.StickyHeaderAdapter {
private final Calendar calendar;
@@ -117,3 +220,4 @@ public class ProfileDocumentsAdapter extends CursorRecyclerViewAdapter, ProfileDocumentsAdapter.ItemClickListener
+{
+ public static final String LOCALE_EXTRA = "locale_extra";
+ public static final String CHAT_ID_EXTRA = "chat_id";
+
+ protected TextView noMedia;
+ protected RecyclerView recyclerView;
+ private ActionMode actionMode;
+ private ActionModeCallback actionModeCallback = new ActionModeCallback();
+
+ protected int chatId;
+ protected Locale locale;
+
+ @Override
+ public void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+
+ chatId = getArguments().getInt(CHAT_ID_EXTRA, -1);
+ locale = (Locale)getArguments().getSerializable(LOCALE_EXTRA);
+ if (locale == null) throw new AssertionError();
+
+ getLoaderManager().initLoader(0, null, this);
+ }
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.profile_documents_fragment, container, false);
+
+ this.recyclerView = ViewUtil.findById(view, R.id.recycler_view);
+ this.noMedia = ViewUtil.findById(view, R.id.no_documents);
+
+ this.recyclerView.setAdapter(new ProfileDocumentsAdapter(getContext(),
+ GlideApp.with(this),
+ new BucketedThreadMediaLoader.BucketedThreadMedia(getContext()),
+ locale,
+ this));
+ this.recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
+ this.recyclerView.setHasFixedSize(true);
+
+ return view;
+ }
+
+ @Override
+ public Loader onCreateLoader(int i, Bundle bundle) {
+ return new BucketedThreadMediaLoader(getContext(), chatId, DcMsg.DC_MSG_FILE, DcMsg.DC_MSG_AUDIO, 0);
+ }
+
+ @Override
+ public void onLoadFinished(Loader loader, BucketedThreadMediaLoader.BucketedThreadMedia bucketedThreadMedia) {
+ ((ProfileDocumentsAdapter) recyclerView.getAdapter()).setMedia(bucketedThreadMedia);
+ ((ProfileDocumentsAdapter) recyclerView.getAdapter()).notifyAllSectionsDataSetChanged();
+
+ noMedia.setVisibility(recyclerView.getAdapter().getItemCount() > 0 ? View.GONE : View.VISIBLE);
+ getActivity().invalidateOptionsMenu();
+ }
+
+ @Override
+ public void onLoaderReset(Loader cursorLoader) {
+ ((ProfileDocumentsAdapter) recyclerView.getAdapter()).setMedia(new BucketedThreadMediaLoader.BucketedThreadMedia(getContext()));
+ }
+
+ @Override
+ public void onMediaClicked(@NonNull DcMsg mediaRecord) {
+ if (actionMode != null) {
+ handleMediaMultiSelectClick(mediaRecord);
+ } else {
+ handleMediaPreviewClick(mediaRecord);
+ }
+ }
+
+ private void handleMediaMultiSelectClick(@NonNull DcMsg mediaRecord) {
+ ProfileDocumentsAdapter adapter = getListAdapter();
+
+ adapter.toggleSelection(mediaRecord);
+ if (adapter.getSelectedMediaCount() == 0) {
+ actionMode.finish();
+ actionMode = null;
+ } else {
+ actionMode.setTitle(String.valueOf(adapter.getSelectedMediaCount()));
+ }
+ }
+
+ private void handleMediaPreviewClick(@NonNull DcMsg mediaRecord) {
+ if (mediaRecord.getFile() == null) {
+ return;
+ }
+
+ Context context = getContext();
+ if (context == null) {
+ return;
+ }
+
+ Intent intent = new Intent(context, MediaPreviewActivity.class);
+ intent.putExtra(MediaPreviewActivity.DC_MSG_ID, mediaRecord.getId());
+ intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, Address.fromChat(chatId));
+ intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
+ intent.putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, false);
+ context.startActivity(intent);
+ }
+
+ @Override
+ public void onMediaLongClicked(DcMsg mediaRecord) {
+ if (actionMode == null) {
+ ((ProfileDocumentsAdapter) recyclerView.getAdapter()).toggleSelection(mediaRecord);
+ recyclerView.getAdapter().notifyDataSetChanged();
+
+ actionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(actionModeCallback);
+ }
+ }
+
+ @SuppressLint("StaticFieldLeak")
+ private void handleDeleteMedia(@NonNull Collection mediaRecords) {
+ int recordCount = mediaRecords.size();
+ Resources res = getContext().getResources();
+ String confirmMessage = res.getQuantityString(R.plurals.ask_delete_messages,
+ recordCount,
+ recordCount);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
+ builder.setMessage(confirmMessage);
+ builder.setCancelable(true);
+ final DcContext dcContext = DcHelper.getContext(getContext());
+
+ builder.setPositiveButton(R.string.delete, (dialogInterface, i) -> {
+ new ProgressDialogAsyncTask(getContext(),
+ R.string.one_moment,
+ R.string.one_moment)
+ {
+ @Override
+ protected Void doInBackground(DcMsg... records) {
+ if (records == null || records.length == 0) {
+ return null;
+ }
+
+ for (DcMsg record : records) {
+ dcContext.deleteMsgs(new int[]{record.getId()});
+ }
+ return null;
+ }
+
+ }.execute(mediaRecords.toArray(new DcMsg[mediaRecords.size()]));
+ });
+ builder.setNegativeButton(android.R.string.cancel, null);
+ builder.show();
+ }
+
+ private ProfileDocumentsAdapter getListAdapter() {
+ return (ProfileDocumentsAdapter) recyclerView.getAdapter();
+ }
+
+ private class ActionModeCallback implements ActionMode.Callback {
+
+ private int originalStatusBarColor;
+
+ @Override
+ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+ mode.getMenuInflater().inflate(R.menu.profile_context, menu);
+ mode.setTitle("1");
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ Window window = getActivity().getWindow();
+ originalStatusBarColor = window.getStatusBarColor();
+ window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+ return false;
+ }
+
+ @Override
+ public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) {
+ switch (menuItem.getItemId()) {
+ case R.id.delete:
+ handleDeleteMedia(getListAdapter().getSelectedMedia());
+ mode.finish();
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void onDestroyActionMode(ActionMode mode) {
+ actionMode = null;
+ getListAdapter().clearSelection();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getActivity().getWindow().setStatusBarColor(originalStatusBarColor);
+ }
+ }
+ }
+}
+
+
+/*
public class ProfileDocumentsFragment extends Fragment implements LoaderManager.LoaderCallbacks {
public static final String LOCALE_EXTRA = "locale_extra";
@@ -76,7 +289,7 @@ public class ProfileDocumentsFragment extends Fragment implements LoaderManager.
getActivity().invalidateOptionsMenu();
// TODO: onLoadFinished() should no take a cursor but forward the loaded messages in a way
- this.noMedia.setVisibility(/*data.getCount() > 0 ? View.GONE :*/ View.VISIBLE);
+ this.noMedia.setVisibility(data.getCount() > 0 ? View.GONE : View.VISIBLE);
}
@Override
@@ -85,3 +298,4 @@ public class ProfileDocumentsFragment extends Fragment implements LoaderManager.
getActivity().invalidateOptionsMenu();
}
}
+*/
\ No newline at end of file
diff --git a/src/org/thoughtcrime/securesms/ProfileGalleryAdapter.java b/src/org/thoughtcrime/securesms/ProfileGalleryAdapter.java
index fd88793d6..df60bde54 100644
--- a/src/org/thoughtcrime/securesms/ProfileGalleryAdapter.java
+++ b/src/org/thoughtcrime/securesms/ProfileGalleryAdapter.java
@@ -1,19 +1,3 @@
-/*
- * Copyright (C) 2015 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
package org.thoughtcrime.securesms;
import android.content.Context;
@@ -90,7 +74,7 @@ class ProfileGalleryAdapter extends StickyHeaderGridAdapter {
@Override
public StickyHeaderGridAdapter.HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent, int headerType) {
- return new HeaderHolder(LayoutInflater.from(context).inflate(R.layout.profile_gallery_item_header, parent, false));
+ return new HeaderHolder(LayoutInflater.from(context).inflate(R.layout.profile_item_header, parent, false));
}
@Override
diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java
index afea4577c..36f88b79e 100644
--- a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java
+++ b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java
@@ -50,13 +50,13 @@ public class ProfileSettingsFragment extends Fragment implements LoaderManager.L
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profile_settings_fragment, container, false);
- ProfileDocumentsAdapter adapter = new ProfileDocumentsAdapter(getContext(), null, locale);
+ //ProfileDocumentsAdapter adapter = new ProfileDocumentsAdapter(getContext(), null, locale);
this.recyclerView = ViewUtil.findById(view, R.id.recycler_view);
- this.recyclerView.setAdapter(adapter);
+ //this.recyclerView.setAdapter(adapter);
this.recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
- this.recyclerView.addItemDecoration(new StickyHeaderDecoration(adapter, false, true));
+ //this.recyclerView.addItemDecoration(new StickyHeaderDecoration(adapter, false, true));
this.recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
return view;