Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 1 | /* |
Sébastien Blin | ab53ada | 2019-01-02 17:23:00 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2019 Savoir-faire Linux Inc. |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 3 | * |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 4 | * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> |
| 5 | * |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 20 | package cx.ring.fragments; |
| 21 | |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 22 | import android.Manifest; |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 23 | import android.animation.ValueAnimator; |
Rayan Osseiran | e445027 | 2019-06-03 14:17:19 -0400 | [diff] [blame] | 24 | import android.content.ActivityNotFoundException; |
Adrien Béraud | ae45ffa | 2018-07-06 16:21:29 -0400 | [diff] [blame] | 25 | import android.content.ClipData; |
Adrien Béraud | 1b8ac9f | 2018-05-31 14:34:23 -0400 | [diff] [blame] | 26 | import android.content.Context; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 27 | import android.content.Intent; |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 28 | import android.content.SharedPreferences; |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 30 | import android.graphics.drawable.BitmapDrawable; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 31 | import android.os.Bundle; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 32 | import android.provider.MediaStore; |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 33 | import android.text.Editable; |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 34 | import android.text.TextUtils; |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 35 | import android.text.TextWatcher; |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 36 | import android.util.Log; |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 37 | import android.view.LayoutInflater; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 38 | import android.view.Menu; |
| 39 | import android.view.MenuInflater; |
| 40 | import android.view.MenuItem; |
| 41 | import android.view.View; |
| 42 | import android.view.ViewGroup; |
| 43 | import android.view.inputmethod.EditorInfo; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 44 | import android.widget.Spinner; |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 45 | import android.widget.Toast; |
| 46 | |
Rayan Osseiran | e445027 | 2019-06-03 14:17:19 -0400 | [diff] [blame] | 47 | import com.google.android.material.snackbar.Snackbar; |
| 48 | |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 49 | import androidx.annotation.NonNull; |
| 50 | import androidx.annotation.Nullable; |
| 51 | import androidx.appcompat.app.ActionBar; |
| 52 | import androidx.appcompat.app.AppCompatActivity; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 53 | import androidx.appcompat.view.menu.MenuBuilder; |
| 54 | import androidx.appcompat.view.menu.MenuPopupHelper; |
| 55 | import androidx.appcompat.widget.PopupMenu; |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 56 | import androidx.core.content.FileProvider; |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 57 | import androidx.core.view.ViewCompat; |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 58 | import androidx.recyclerview.widget.DefaultItemAnimator; |
| 59 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 60 | import java.io.File; |
| 61 | import java.io.IOException; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 62 | import java.util.List; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 63 | |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 64 | import butterknife.OnEditorAction; |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 65 | import cx.ring.BuildConfig; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 66 | import cx.ring.R; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 67 | import cx.ring.adapters.ConversationAdapter; |
| 68 | import cx.ring.adapters.NumberAdapter; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 69 | import cx.ring.application.JamiApplication; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 70 | import cx.ring.client.CallActivity; |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 71 | import cx.ring.client.ContactDetailsActivity; |
Aline Bonnet | 830c4c6 | 2016-12-27 14:02:02 -0500 | [diff] [blame] | 72 | import cx.ring.client.ConversationActivity; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 73 | import cx.ring.client.HomeActivity; |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 74 | import cx.ring.contacts.AvatarFactory; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 75 | import cx.ring.conversation.ConversationPresenter; |
| 76 | import cx.ring.conversation.ConversationView; |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 77 | import cx.ring.databinding.FragConversationBinding; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 78 | import cx.ring.dependencyinjection.JamiInjectionComponent; |
Adrien Béraud | 171ba36 | 2018-12-14 21:35:40 -0500 | [diff] [blame] | 79 | import cx.ring.interfaces.Colorable; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 80 | import cx.ring.model.CallContact; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 81 | import cx.ring.model.Conversation; |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 82 | import cx.ring.model.Interaction; |
Adrien Béraud | 2153329 | 2018-03-22 14:11:35 -0400 | [diff] [blame] | 83 | import cx.ring.model.DataTransfer; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 84 | import cx.ring.model.Phone; |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 85 | import cx.ring.model.RingError; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 86 | import cx.ring.model.Uri; |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 87 | import cx.ring.mvp.BaseSupportFragment; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 88 | import cx.ring.services.NotificationService; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 89 | import cx.ring.utils.ActionHelper; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 90 | import cx.ring.utils.AndroidFileUtils; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 91 | import cx.ring.utils.ContentUriHandler; |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 92 | import cx.ring.utils.MediaButtonsHelper; |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 93 | import io.reactivex.Completable; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 94 | import io.reactivex.Single; |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 95 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 96 | import io.reactivex.disposables.Disposable; |
Rayan Osseiran | ed9feeb | 2019-07-05 16:04:30 -0400 | [diff] [blame] | 97 | import io.reactivex.schedulers.Schedulers; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 98 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 99 | import static android.app.Activity.RESULT_OK; |
| 100 | |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 101 | public class ConversationFragment extends BaseSupportFragment<ConversationPresenter> implements |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 102 | MediaButtonsHelper.MediaButtonsHelperCallback, |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 103 | ConversationView, SharedPreferences.OnSharedPreferenceChangeListener { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 104 | protected static final String TAG = ConversationFragment.class.getSimpleName(); |
| 105 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 106 | public static final int REQ_ADD_CONTACT = 42; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 107 | |
Adrien Béraud | 6ac6363 | 2018-12-09 00:11:21 -0500 | [diff] [blame] | 108 | public static final String KEY_CONTACT_RING_ID = BuildConfig.APPLICATION_ID + ".CONTACT_RING_ID"; |
| 109 | public static final String KEY_ACCOUNT_ID = BuildConfig.APPLICATION_ID + ".ACCOUNT_ID"; |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 110 | public static final String KEY_PREFERENCE_PENDING_MESSAGE = "pendingMessage"; |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 111 | public static final String KEY_PREFERENCE_CONVERSATION_COLOR = "color"; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 112 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 113 | private static final int REQUEST_CODE_FILE_PICKER = 1000; |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 114 | private static final int REQUEST_PERMISSION_CAMERA = 1001; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 115 | private static final int REQUEST_CODE_TAKE_PICTURE = 1002; |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 116 | private static final int REQUEST_CODE_SAVE_FILE = 1003; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 117 | private static final int REQUEST_CODE_CAPTURE_AUDIO = 1004; |
| 118 | private static final int REQUEST_CODE_CAPTURE_VIDEO = 1005; |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 119 | |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 120 | private FragConversationBinding binding; |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 121 | private MenuItem mAudioCallBtn = null; |
| 122 | private MenuItem mVideoCallBtn = null; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 123 | |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 124 | private View currentBottomView = null; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 125 | private ConversationAdapter mAdapter = null; |
| 126 | private NumberAdapter mNumberAdapter = null; |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 127 | private int marginPx; |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 128 | private int marginPxTotal; |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 129 | private final ValueAnimator animation = new ValueAnimator(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 130 | |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 131 | private SharedPreferences mPreferences; |
| 132 | |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 133 | private File mCurrentPhoto = null; |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 134 | private String mCurrentFileAbsolutePath = null; |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 135 | private Disposable actionbarTarget = null; |
Adrien Béraud | 742d320 | 2019-11-15 14:28:59 -0500 | [diff] [blame] | 136 | private int mSelectedPosition; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 137 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 138 | private static int getIndex(Spinner spinner, Uri myString) { |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 139 | for (int i = 0, n = spinner.getCount(); i < n; i++) |
| 140 | if (((Phone) spinner.getItemAtPosition(i)).getNumber().equals(myString)) { |
| 141 | return i; |
| 142 | } |
| 143 | return 0; |
| 144 | } |
| 145 | |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 146 | @Override |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 147 | public void refreshView(final List<Interaction> conversation) { |
Adrien Béraud | 20d4221 | 2018-03-02 14:40:38 -0500 | [diff] [blame] | 148 | if (conversation == null) { |
| 149 | return; |
| 150 | } |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 151 | if (binding != null) |
| 152 | binding.pbLoading.setVisibility(View.GONE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 153 | if (mAdapter != null) { |
| 154 | mAdapter.updateDataset(conversation); |
| 155 | } |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 156 | requireActivity().invalidateOptionsMenu(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 157 | } |
| 158 | |
Aline Bonnet | e8e87f6 | 2016-12-26 10:54:37 -0500 | [diff] [blame] | 159 | @Override |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 160 | public void scrollToEnd() { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 161 | if (mAdapter.getItemCount() > 0) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 162 | binding.histList.scrollToPosition(mAdapter.getItemCount() - 1); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 163 | } |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Override |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 167 | public int getLayout() { |
| 168 | return R.layout.frag_conversation; |
| 169 | } |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 170 | |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 171 | @Override |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 172 | public void injectFragment(JamiInjectionComponent component) { |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 173 | component.inject(this); |
| 174 | } |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 175 | |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 176 | private static void setBottomPadding(@NonNull View view, int padding) { |
| 177 | view.setPadding( |
| 178 | view.getPaddingLeft(), |
| 179 | view.getPaddingTop(), |
| 180 | view.getPaddingRight(), |
| 181 | padding); |
| 182 | } |
| 183 | |
| 184 | private void updateListPadding() { |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 185 | if (currentBottomView != null && currentBottomView.getHeight() != 0) |
| 186 | setBottomPadding(binding.histList, currentBottomView.getHeight() + marginPxTotal); |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 189 | @Nullable |
| 190 | @Override |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 191 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 192 | injectFragment(((JamiApplication) getActivity().getApplication()).getRingInjectionComponent()); |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 193 | marginPx = getResources().getDimensionPixelSize(R.dimen.conversation_message_input_margin); |
| 194 | marginPxTotal = marginPx; |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 195 | |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 196 | binding = FragConversationBinding.inflate(inflater, container, false); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 197 | binding.setPresenter(this); |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 198 | |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 199 | animation.setDuration(150); |
| 200 | animation.addUpdateListener(valueAnimator -> setBottomPadding(binding.histList, (Integer)valueAnimator.getAnimatedValue())); |
| 201 | |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 202 | ViewCompat.setOnApplyWindowInsetsListener(binding.histList, (v, insets) -> { |
| 203 | marginPxTotal = marginPx + insets.getSystemWindowInsetBottom(); |
| 204 | updateListPadding(); |
| 205 | insets.consumeSystemWindowInsets(); |
| 206 | return insets; |
| 207 | }); |
| 208 | int paddingTop = binding.conversationLayout.getPaddingTop(); |
| 209 | ViewCompat.setOnApplyWindowInsetsListener(binding.conversationLayout, (v, insets) -> { |
| 210 | v.setPadding( |
| 211 | v.getPaddingLeft(), |
| 212 | paddingTop + insets.getSystemWindowInsetTop(), |
| 213 | v.getPaddingRight(), |
| 214 | v.getPaddingBottom()); |
| 215 | insets.consumeSystemWindowInsets(); |
| 216 | return insets; |
| 217 | }); |
| 218 | |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 219 | binding.ongoingcallPane.setVisibility(View.GONE); |
Adrien Béraud | 1af6c01 | 2019-05-25 23:20:29 -0400 | [diff] [blame] | 220 | binding.msgInputTxt.setMediaListener(contentInfo -> startFileSend(AndroidFileUtils |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 221 | .getCacheFile(requireContext(), contentInfo.getContentUri()) |
| 222 | .flatMapCompletable(this::sendFile) |
| 223 | .doFinally(contentInfo::releasePermission))); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 224 | binding.msgInputTxt.setOnEditorActionListener((v, actionId, event) -> actionSendMsgText(actionId)); |
| 225 | binding.msgInputTxt.addTextChangedListener(new TextWatcher() { |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 226 | @Override |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 227 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 228 | } |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 229 | |
| 230 | @Override |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 231 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 232 | } |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 233 | |
| 234 | @Override |
| 235 | public void afterTextChanged(Editable s) { |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 236 | String message = s.toString(); |
Adrien Béraud | e09dd01 | 2019-11-15 14:57:18 -0500 | [diff] [blame^] | 237 | boolean hasMessage = !TextUtils.isEmpty(message); |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 238 | if (hasMessage) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 239 | binding.msgSend.setVisibility(View.VISIBLE); |
| 240 | binding.emojiSend.setVisibility(View.GONE); |
Adrien Béraud | e09dd01 | 2019-11-15 14:57:18 -0500 | [diff] [blame^] | 241 | } else { |
| 242 | binding.msgSend.setVisibility(View.GONE); |
| 243 | binding.emojiSend.setVisibility(View.VISIBLE); |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 244 | } |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 245 | if (mPreferences != null) { |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 246 | if (hasMessage) |
| 247 | mPreferences.edit().putString(KEY_PREFERENCE_PENDING_MESSAGE, message).apply(); |
| 248 | else |
| 249 | mPreferences.edit().remove(KEY_PREFERENCE_PENDING_MESSAGE).apply(); |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | }); |
Adrien Béraud | 9d4a81f | 2018-07-09 01:19:52 -0400 | [diff] [blame] | 253 | |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 254 | setHasOptionsMenu(true); |
| 255 | return binding.getRoot(); |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { |
| 260 | super.onViewCreated(view, savedInstanceState); |
| 261 | |
| 262 | if (mPreferences != null) { |
| 263 | String pendingMessage = mPreferences.getString(KEY_PREFERENCE_PENDING_MESSAGE, null); |
| 264 | if (!TextUtils.isEmpty(pendingMessage)) { |
| 265 | binding.msgInputTxt.setText(pendingMessage); |
| 266 | binding.msgSend.setVisibility(View.VISIBLE); |
| 267 | binding.emojiSend.setVisibility(View.GONE); |
| 268 | } |
| 269 | } |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 270 | |
| 271 | binding.msgInputTxt.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 272 | if (oldBottom == 0 && oldTop == 0) { |
| 273 | updateListPadding(); |
| 274 | } else { |
| 275 | if (animation.isStarted()) |
| 276 | animation.cancel(); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 277 | animation.setIntValues(binding.histList.getPaddingBottom(), (currentBottomView == null ? 0 : currentBottomView.getHeight()) + marginPxTotal); |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 278 | animation.start(); |
| 279 | } |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 280 | }); |
| 281 | |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 282 | DefaultItemAnimator animator = (DefaultItemAnimator) binding.histList.getItemAnimator(); |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 283 | if (animator != null) |
| 284 | animator.setSupportsChangeAnimations(false); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 285 | binding.histList.setAdapter(mAdapter); |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 286 | } |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 287 | |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 288 | @Override |
| 289 | public void setConversationColor(int color) { |
Adrien Béraud | 171ba36 | 2018-12-14 21:35:40 -0500 | [diff] [blame] | 290 | Colorable activity = (Colorable) getActivity(); |
| 291 | if (activity != null) |
| 292 | activity.setColor(color); |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 293 | mAdapter.setPrimaryColor(color); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Adrien Béraud | 7c50511 | 2018-03-20 16:03:28 -0400 | [diff] [blame] | 296 | @Override |
Adrien Béraud | 4030d2e | 2018-12-02 23:08:03 -0500 | [diff] [blame] | 297 | public void onDestroyView() { |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 298 | if (mPreferences != null) |
| 299 | mPreferences.unregisterOnSharedPreferenceChangeListener(this); |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 300 | animation.removeAllUpdateListeners(); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 301 | binding.histList.setAdapter(null); |
Adrien Béraud | 4030d2e | 2018-12-02 23:08:03 -0500 | [diff] [blame] | 302 | super.onDestroyView(); |
| 303 | } |
| 304 | |
| 305 | @Override |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 306 | public boolean onContextItemSelected(@NonNull MenuItem item) { |
Adrien Béraud | 7c50511 | 2018-03-20 16:03:28 -0400 | [diff] [blame] | 307 | if (mAdapter.onContextItemSelected(item)) |
| 308 | return true; |
| 309 | return super.onContextItemSelected(item); |
| 310 | } |
| 311 | |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 312 | public void updateAdapterItem() { |
Adrien Béraud | 742d320 | 2019-11-15 14:28:59 -0500 | [diff] [blame] | 313 | if (mSelectedPosition != -1) { |
| 314 | mAdapter.notifyItemChanged(mSelectedPosition); |
| 315 | mSelectedPosition = -1; |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
Alexandre Lision | 66a9f9a | 2017-02-26 20:28:27 -0500 | [diff] [blame] | 319 | public void sendMessageText() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 320 | String message = binding.msgInputTxt.getText().toString(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 321 | clearMsgEdit(); |
| 322 | presenter.sendTextMessage(message); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 323 | } |
| 324 | |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 325 | public void sendEmoji() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 326 | presenter.sendTextMessage(binding.emojiSend.getText().toString()); |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 327 | } |
| 328 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 329 | public void selectFile() { |
| 330 | presenter.selectFile(); |
| 331 | } |
| 332 | |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 333 | public void expandMenu(View v) { |
| 334 | Context context = requireContext(); |
| 335 | PopupMenu popup = new PopupMenu(context, v); |
| 336 | popup.inflate(R.menu.conversation_share_actions); |
| 337 | popup.setOnMenuItemClickListener(item -> { |
| 338 | switch(item.getItemId()) { |
| 339 | case R.id.conv_send_audio: { |
| 340 | Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); |
| 341 | if (intent.resolveActivity(context.getPackageManager()) != null) { |
| 342 | try { |
| 343 | mCurrentPhoto = AndroidFileUtils.createAudioFile(context); |
| 344 | } catch (IOException ex) { |
| 345 | Log.e(TAG, "takePicture: error creating temporary file", ex); |
| 346 | break; |
| 347 | } |
| 348 | //intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(context, ContentUriHandler.AUTHORITY_FILES, mCurrentPhoto)); |
| 349 | startActivityForResult(intent, REQUEST_CODE_CAPTURE_AUDIO); |
| 350 | } else { |
| 351 | Toast.makeText(getActivity(), "Can't find audio recorder app", Toast.LENGTH_SHORT).show(); |
| 352 | } |
| 353 | break; |
| 354 | } |
| 355 | case R.id.conv_send_video: { |
| 356 | Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); |
| 357 | intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); |
| 358 | intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1); |
| 359 | intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true); |
| 360 | if (intent.resolveActivity(context.getPackageManager()) != null) { |
| 361 | try { |
| 362 | mCurrentPhoto = AndroidFileUtils.createVideoFile(context); |
| 363 | } catch (IOException ex) { |
| 364 | Log.e(TAG, "takePicture: error creating temporary file", ex); |
| 365 | break; |
| 366 | } |
| 367 | intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(context, ContentUriHandler.AUTHORITY_FILES, mCurrentPhoto)); |
| 368 | startActivityForResult(intent, REQUEST_CODE_CAPTURE_VIDEO); |
| 369 | } else { |
| 370 | Toast.makeText(getActivity(), "Can't find video recorder app", Toast.LENGTH_SHORT).show(); |
| 371 | } |
| 372 | break; |
| 373 | } |
| 374 | case R.id.conv_send_file: |
| 375 | selectFile(); |
| 376 | break; |
| 377 | } |
| 378 | return false; |
| 379 | }); |
| 380 | MenuPopupHelper menuHelper = new MenuPopupHelper(context, (MenuBuilder) popup.getMenu(), v); |
| 381 | menuHelper.setForceShowIcon(true); |
| 382 | menuHelper.show(); |
| 383 | } |
| 384 | |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 385 | /** |
| 386 | * Used to update with the past adapter position when a long click was registered |
| 387 | * @param position |
| 388 | */ |
| 389 | public void updatePosition(int position) { |
Adrien Béraud | 742d320 | 2019-11-15 14:28:59 -0500 | [diff] [blame] | 390 | mSelectedPosition = position; |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 391 | } |
| 392 | |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 393 | public void takePicture() { |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 394 | if (!presenter.getDeviceRuntimeService().hasVideoPermission()) { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 395 | requestPermissions(new String[]{Manifest.permission.CAMERA}, JamiApplication.PERMISSIONS_REQUEST); |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 396 | } else { |
Adrien Béraud | f5c32f9 | 2019-01-03 23:40:00 -0500 | [diff] [blame] | 397 | Context c = getContext(); |
| 398 | if (c == null) |
| 399 | return; |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 400 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
Adrien Béraud | f5c32f9 | 2019-01-03 23:40:00 -0500 | [diff] [blame] | 401 | if (takePictureIntent.resolveActivity(c.getPackageManager()) != null) { |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 402 | // Create the File where the photo should go |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 403 | File photoFile; |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 404 | try { |
Adrien Béraud | f5c32f9 | 2019-01-03 23:40:00 -0500 | [diff] [blame] | 405 | photoFile = AndroidFileUtils.createImageFile(c); |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 406 | } catch (IOException ex) { |
| 407 | Log.e(TAG, "takePicture: error creating temporary file", ex); |
| 408 | return; |
| 409 | } |
| 410 | Log.i(TAG, "takePicture: trying to save to " + photoFile); |
| 411 | mCurrentPhoto = photoFile; |
Adrien Béraud | f5c32f9 | 2019-01-03 23:40:00 -0500 | [diff] [blame] | 412 | android.net.Uri photoURI = FileProvider.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, photoFile); |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 413 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); |
| 414 | startActivityForResult(takePictureIntent, REQUEST_CODE_TAKE_PICTURE); |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 415 | } |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 419 | @Override |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 420 | public void askWriteExternalStoragePermission() { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 421 | requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, JamiApplication.PERMISSIONS_REQUEST); |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | @Override |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 425 | public void openFilePicker() { |
| 426 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); |
| 427 | intent.addCategory(Intent.CATEGORY_OPENABLE); |
| 428 | intent.setType("*/*"); |
| 429 | |
| 430 | startActivityForResult(intent, REQUEST_CODE_FILE_PICKER); |
| 431 | } |
| 432 | |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 433 | private Completable sendFile(File file) { |
| 434 | return Completable.fromAction(() -> presenter.sendFile(file)); |
| 435 | } |
| 436 | |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 437 | private void startFileSend(Completable op) { |
| 438 | setLoading(true); |
Adrien Béraud | 1af6c01 | 2019-05-25 23:20:29 -0400 | [diff] [blame] | 439 | op.observeOn(AndroidSchedulers.mainThread()) |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 440 | .doFinally(() -> setLoading(false)) |
| 441 | .subscribe(() -> {}, e -> { |
| 442 | Log.e(TAG, "startFileSend: not able to create cache file", e); |
| 443 | displayErrorToast(RingError.INVALID_FILE); |
| 444 | }); |
| 445 | } |
| 446 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 447 | @Override |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 448 | public void onActivityResult(int requestCode, int resultCode, Intent resultData) { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 449 | Log.w(TAG, "onActivityResult: " + requestCode + " " + resultCode + " " + resultData); |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 450 | super.onActivityResult(requestCode, resultCode, resultData); |
| 451 | |
| 452 | if (requestCode == REQUEST_CODE_FILE_PICKER && resultCode == RESULT_OK) { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 453 | if (resultData == null) { |
| 454 | return; |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 455 | } |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 456 | android.net.Uri uri = resultData.getData(); |
| 457 | if (uri == null) { |
| 458 | return; |
| 459 | } |
Adrien Béraud | 1af6c01 | 2019-05-25 23:20:29 -0400 | [diff] [blame] | 460 | startFileSend(AndroidFileUtils.getCacheFile(requireContext(), uri) |
| 461 | .observeOn(AndroidSchedulers.mainThread()) |
| 462 | .flatMapCompletable(this::sendFile)); |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 463 | } else if (requestCode == REQUEST_CODE_TAKE_PICTURE |
| 464 | || requestCode == REQUEST_CODE_CAPTURE_AUDIO |
| 465 | || requestCode == REQUEST_CODE_CAPTURE_VIDEO) { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 466 | if (resultCode != RESULT_OK) { |
| 467 | mCurrentPhoto = null; |
| 468 | return; |
| 469 | } |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 470 | Log.w(TAG, "onActivityResult: mCurrentPhoto " + mCurrentPhoto.getAbsolutePath() + " " + mCurrentPhoto.exists() + " " + mCurrentPhoto.length()); |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 471 | Single<File> file = null; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 472 | if (mCurrentPhoto == null || !mCurrentPhoto.exists() || mCurrentPhoto.length() == 0) { |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 473 | android.net.Uri createdUri = resultData.getData(); |
| 474 | if (createdUri != null) { |
| 475 | file = AndroidFileUtils.getCacheFile(requireContext(), createdUri); |
| 476 | } |
| 477 | } else { |
| 478 | file = Single.just(mCurrentPhoto); |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 479 | } |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 480 | mCurrentPhoto = null; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 481 | if (file == null) { |
| 482 | Toast.makeText(getActivity(), "Can't find picture", Toast.LENGTH_SHORT).show(); |
| 483 | return; |
| 484 | } |
| 485 | startFileSend(file.flatMapCompletable(this::sendFile)); |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 486 | } |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 487 | // File download trough SAF |
| 488 | else if(requestCode == ConversationFragment.REQUEST_CODE_SAVE_FILE |
| 489 | && resultCode == RESULT_OK){ |
| 490 | if(resultData != null && resultData.getData() != null ) { |
| 491 | //Get the Uri of the file that was created by the app that received our intent |
| 492 | android.net.Uri createdUri = resultData.getData(); |
| 493 | |
| 494 | //Try to copy the data of the current file into the newly created one |
| 495 | File input = new File(mCurrentFileAbsolutePath); |
| 496 | if(requireContext().getContentResolver() != null) |
| 497 | AndroidFileUtils.copyFileToUri( |
| 498 | requireContext().getContentResolver(),input,createdUri). |
| 499 | observeOn(AndroidSchedulers.mainThread()). |
| 500 | subscribe(()->Toast.makeText(getContext(), R.string.file_saved_successfully, |
| 501 | Toast.LENGTH_SHORT).show(), |
| 502 | error->Toast.makeText(getContext(), R.string.generic_error, |
| 503 | Toast.LENGTH_SHORT).show()); |
| 504 | |
| 505 | } |
| 506 | } |
| 507 | |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | @Override |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 511 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| 512 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 513 | for (int i = 0, n = permissions.length; i < n; i++) { |
| 514 | switch (permissions[i]) { |
| 515 | case Manifest.permission.CAMERA: |
| 516 | boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 517 | presenter.cameraPermissionChanged(granted); |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 518 | if (granted) { |
| 519 | takePicture(); |
| 520 | } |
| 521 | return; |
| 522 | default: |
| 523 | break; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | @Override |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 529 | public void addElement(Interaction element) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 530 | mAdapter.add(element); |
| 531 | scrollToEnd(); |
| 532 | } |
Adrien Béraud | 3cbc7fa | 2018-07-18 18:36:21 -0400 | [diff] [blame] | 533 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 534 | @Override |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 535 | public void updateElement(Interaction element) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 536 | mAdapter.update(element); |
| 537 | } |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 538 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 539 | @Override |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 540 | public void removeElement(Interaction element) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 541 | mAdapter.remove(element); |
Adrien Béraud | 2153329 | 2018-03-22 14:11:35 -0400 | [diff] [blame] | 542 | } |
| 543 | |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 544 | @Override |
| 545 | public void shareFile(File path) { |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 546 | Context c = getContext(); |
| 547 | if (c == null) |
| 548 | return; |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 549 | android.net.Uri fileUri = null; |
| 550 | try { |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 551 | fileUri = FileProvider.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, path); |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 552 | } catch (IllegalArgumentException e) { |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 553 | Log.e("File Selector", "The selected file can't be shared: " + path.getName()); |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 554 | } |
| 555 | if (fileUri != null) { |
| 556 | Intent sendIntent = new Intent(); |
| 557 | sendIntent.setAction(Intent.ACTION_SEND); |
| 558 | sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 559 | String type = c.getContentResolver().getType(fileUri); |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 560 | sendIntent.setDataAndType(fileUri, type); |
| 561 | sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); |
| 562 | startActivity(Intent.createChooser(sendIntent, null)); |
| 563 | } |
| 564 | } |
| 565 | |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 566 | @Override |
| 567 | public void openFile(File path) { |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 568 | Context c = getContext(); |
| 569 | if (c == null) |
| 570 | return; |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 571 | android.net.Uri fileUri = null; |
| 572 | try { |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 573 | fileUri = FileProvider.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, path); |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 574 | } catch (IllegalArgumentException e) { |
| 575 | Log.e("File Selector", "The selected file can't be shared: " + path.getName()); |
| 576 | } |
| 577 | if (fileUri != null) { |
| 578 | Intent sendIntent = new Intent(); |
| 579 | sendIntent.setAction(Intent.ACTION_VIEW); |
| 580 | sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 581 | String type = c.getContentResolver().getType(fileUri); |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 582 | sendIntent.setDataAndType(fileUri, type); |
| 583 | sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); |
| 584 | //startActivity(Intent.createChooser(sendIntent, null)); |
Rayan Osseiran | e445027 | 2019-06-03 14:17:19 -0400 | [diff] [blame] | 585 | try { |
| 586 | startActivity(sendIntent); |
| 587 | } catch (ActivityNotFoundException e) { |
| 588 | Snackbar.make(getView(), R.string.conversation_open_file_error, Snackbar.LENGTH_LONG).show(); |
| 589 | Log.e("File Loader", "File of unknown type, could not open: " + path.getName()); |
| 590 | } |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 594 | @OnEditorAction(R.id.msg_input_txt) |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 595 | boolean actionSendMsgText(int actionId) { |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 596 | switch (actionId) { |
| 597 | case EditorInfo.IME_ACTION_SEND: |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 598 | sendMessageText(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 599 | return true; |
| 600 | } |
| 601 | return false; |
| 602 | } |
| 603 | |
Alexandre Lision | 66a9f9a | 2017-02-26 20:28:27 -0500 | [diff] [blame] | 604 | public void onClick() { |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 605 | presenter.clickOnGoingPane(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public void onPause() { |
| 610 | super.onPause(); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 611 | presenter.pause(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | @Override |
| 615 | public void onResume() { |
| 616 | super.onResume(); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 617 | presenter.resume(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | @Override |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 621 | public void onDetach() { |
| 622 | if (actionbarTarget != null) { |
| 623 | actionbarTarget.dispose(); |
| 624 | actionbarTarget = null; |
| 625 | } |
| 626 | super.onDetach(); |
| 627 | } |
| 628 | |
| 629 | @Override |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 630 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 631 | inflater.inflate(R.menu.conversation_actions, menu); |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 632 | mAudioCallBtn = menu.findItem(R.id.conv_action_audiocall); |
| 633 | mVideoCallBtn = menu.findItem(R.id.conv_action_videocall); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public boolean onOptionsItemSelected(MenuItem item) { |
| 638 | switch (item.getItemId()) { |
| 639 | case android.R.id.home: |
| 640 | startActivity(new Intent(getActivity(), HomeActivity.class)); |
| 641 | return true; |
| 642 | case R.id.conv_action_audiocall: |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 643 | presenter.callWithAudioOnly(true); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 644 | return true; |
| 645 | case R.id.conv_action_videocall: |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 646 | presenter.callWithAudioOnly(false); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 647 | return true; |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 648 | case R.id.conv_contact_details: |
| 649 | presenter.openContact(); |
Aline Bonnet | 54cf69b | 2017-03-28 12:03:45 -0400 | [diff] [blame] | 650 | return true; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 651 | default: |
| 652 | return super.onOptionsItemSelected(item); |
| 653 | } |
| 654 | } |
| 655 | |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 656 | @Override |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 657 | protected void initPresenter(ConversationPresenter presenter) { |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 658 | Bundle args = getArguments(); |
| 659 | if (args == null) |
| 660 | return; |
| 661 | Uri contactUri = new Uri(args.getString(KEY_CONTACT_RING_ID)); |
| 662 | String accountId = args.getString(KEY_ACCOUNT_ID); |
| 663 | mAdapter = new ConversationAdapter(this, presenter); |
| 664 | presenter.init(contactUri, accountId); |
Adrien Béraud | 56c3413 | 2018-11-29 13:32:00 -0500 | [diff] [blame] | 665 | try { |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 666 | mPreferences = requireActivity().getSharedPreferences(accountId + "_" + contactUri.getRawRingId(), Context.MODE_PRIVATE); |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 667 | mPreferences.registerOnSharedPreferenceChangeListener(this); |
| 668 | presenter.setConversationColor(mPreferences.getInt(KEY_PREFERENCE_CONVERSATION_COLOR, getResources().getColor(R.color.color_primary_light))); |
Adrien Béraud | 56c3413 | 2018-11-29 13:32:00 -0500 | [diff] [blame] | 669 | } catch (Exception e) { |
| 670 | Log.e(TAG, "Can't load conversation preferences"); |
| 671 | } |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | @Override |
| 675 | public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { |
| 676 | switch (key) { |
| 677 | case KEY_PREFERENCE_CONVERSATION_COLOR: |
| 678 | presenter.setConversationColor(prefs.getInt(KEY_PREFERENCE_CONVERSATION_COLOR, getResources().getColor(R.color.color_primary_light))); |
| 679 | break; |
| 680 | } |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | @Override |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 684 | public void displayContact(final CallContact contact) { |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 685 | ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 686 | if (actionBar == null) { |
| 687 | return; |
| 688 | } |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 689 | Context context = actionBar.getThemedContext(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 690 | String displayName = contact.getDisplayName(); |
| 691 | actionBar.setTitle(displayName); |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 692 | |
| 693 | if (actionbarTarget != null) { |
| 694 | actionbarTarget.dispose(); |
| 695 | actionbarTarget = null; |
| 696 | } |
| 697 | int targetSize = (int) (AvatarFactory.SIZE_AB * context.getResources().getDisplayMetrics().density); |
| 698 | actionbarTarget = AvatarFactory.getBitmapAvatar(context, contact, targetSize) |
Rayan Osseiran | ed9feeb | 2019-07-05 16:04:30 -0400 | [diff] [blame] | 699 | .subscribeOn(Schedulers.computation()) |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 700 | .observeOn(AndroidSchedulers.mainThread()) |
| 701 | .subscribe(b -> actionBar.setLogo(new BitmapDrawable(context.getResources(), b))); |
| 702 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 703 | String identity = contact.getRingUsername(); |
| 704 | if (identity != null && !identity.equals(displayName)) { |
| 705 | actionBar.setSubtitle(identity); |
| 706 | } |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 707 | |
| 708 | mAdapter.setPhoto(); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | @Override |
| 712 | public void displayOnGoingCallPane(final boolean display) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 713 | binding.ongoingcallPane.setVisibility(display ? View.VISIBLE : View.GONE); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | @Override |
| 717 | public void displayNumberSpinner(final Conversation conversation, final Uri number) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 718 | binding.numberSelector.setVisibility(View.VISIBLE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 719 | mNumberAdapter = new NumberAdapter(getActivity(), |
| 720 | conversation.getContact(), |
| 721 | false); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 722 | binding.numberSelector.setAdapter(mNumberAdapter); |
| 723 | binding.numberSelector.setSelection(getIndex(binding.numberSelector, number)); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | @Override |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 727 | public void hideNumberSpinner() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 728 | binding.numberSelector.setVisibility(View.GONE); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | @Override |
| 732 | public void clearMsgEdit() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 733 | binding.msgInputTxt.setText(""); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | @Override |
| 737 | public void goToHome() { |
| 738 | if (getActivity() instanceof ConversationActivity) { |
| 739 | getActivity().finish(); |
Aline Bonnet | eb5f7ff | 2017-01-17 11:09:17 -0500 | [diff] [blame] | 740 | } |
| 741 | } |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 742 | |
| 743 | @Override |
| 744 | public void goToAddContact(CallContact callContact) { |
| 745 | startActivityForResult(ActionHelper.getAddNumberIntentForContact(callContact), REQ_ADD_CONTACT); |
| 746 | } |
| 747 | |
| 748 | @Override |
| 749 | public void goToCallActivity(String conferenceId) { |
| 750 | startActivity(new Intent(Intent.ACTION_VIEW) |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 751 | .setClass(requireActivity().getApplicationContext(), CallActivity.class) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 752 | .putExtra(NotificationService.KEY_CALL_ID, conferenceId)); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | @Override |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 756 | public void goToContactActivity(String accountId, String contactRingId) { |
| 757 | startActivity(new Intent(Intent.ACTION_VIEW, android.net.Uri.withAppendedPath(android.net.Uri.withAppendedPath(ContentUriHandler.CONTACT_CONTENT_URI, accountId), contactRingId)) |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 758 | .setClass(requireActivity().getApplicationContext(), ContactDetailsActivity.class)); |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | @Override |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 762 | public void goToCallActivityWithResult(String accountId, String contactRingId, boolean audioOnly) { |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 763 | Intent intent = new Intent(CallActivity.ACTION_CALL) |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 764 | .setClass(requireActivity().getApplicationContext(), CallActivity.class) |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 765 | .putExtra(KEY_ACCOUNT_ID, accountId) |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 766 | .putExtra(CallFragment.KEY_AUDIO_ONLY, audioOnly) |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 767 | .putExtra(KEY_CONTACT_RING_ID, contactRingId); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 768 | startActivityForResult(intent, HomeActivity.REQUEST_CODE_CALL); |
| 769 | } |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 770 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 771 | public void blockContactRequest() { |
| 772 | presenter.onBlockIncomingContactRequest(); |
| 773 | } |
| 774 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 775 | public void refuseContactRequest() { |
| 776 | presenter.onRefuseIncomingContactRequest(); |
| 777 | } |
| 778 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 779 | public void acceptContactRequest() { |
| 780 | presenter.onAcceptIncomingContactRequest(); |
| 781 | } |
| 782 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 783 | public void addContact() { |
| 784 | presenter.onAddContact(); |
| 785 | } |
| 786 | |
| 787 | @Override |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 788 | public void onPrepareOptionsMenu(Menu menu) { |
| 789 | super.onPrepareOptionsMenu(menu); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 790 | boolean visible = binding.cvMessageInput.getVisibility() == View.VISIBLE; |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 791 | if (mAudioCallBtn != null) |
| 792 | mAudioCallBtn.setVisible(visible); |
| 793 | if (mVideoCallBtn != null) |
| 794 | mVideoCallBtn.setVisible(visible); |
| 795 | } |
| 796 | |
| 797 | @Override |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 798 | public void switchToUnknownView(String contactDisplayName) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 799 | binding.cvMessageInput.setVisibility(View.GONE); |
| 800 | binding.unknownContactPrompt.setVisibility(View.VISIBLE); |
| 801 | binding.trustRequestPrompt.setVisibility(View.GONE); |
| 802 | binding.tvTrustRequestMessage.setText(String.format(getString(R.string.message_contact_not_trusted), contactDisplayName)); |
| 803 | binding.trustRequestMessageLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 804 | currentBottomView = binding.unknownContactPrompt; |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 805 | requireActivity().invalidateOptionsMenu(); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 806 | updateListPadding(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 807 | } |
| 808 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 809 | @Override |
| 810 | public void switchToIncomingTrustRequestView(String contactDisplayName) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 811 | binding.cvMessageInput.setVisibility(View.GONE); |
| 812 | binding.unknownContactPrompt.setVisibility(View.GONE); |
| 813 | binding.trustRequestPrompt.setVisibility(View.VISIBLE); |
| 814 | binding.tvTrustRequestMessage.setText(String.format(getString(R.string.message_contact_not_trusted_yet), contactDisplayName)); |
| 815 | binding.trustRequestMessageLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 816 | currentBottomView = binding.trustRequestPrompt; |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 817 | requireActivity().invalidateOptionsMenu(); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 818 | updateListPadding(); |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | @Override |
| 822 | public void switchToConversationView() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 823 | binding.cvMessageInput.setVisibility(View.VISIBLE); |
| 824 | binding.unknownContactPrompt.setVisibility(View.GONE); |
| 825 | binding.trustRequestPrompt.setVisibility(View.GONE); |
| 826 | binding.trustRequestMessageLayout.setVisibility(View.GONE); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 827 | currentBottomView = binding.cvMessageInput; |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 828 | requireActivity().invalidateOptionsMenu(); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 829 | updateListPadding(); |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | @Override |
| 833 | public void positiveMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 834 | presenter.clickOnGoingPane(); |
| 835 | } |
| 836 | |
| 837 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 838 | public void negativeMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 839 | presenter.clickOnGoingPane(); |
| 840 | } |
| 841 | |
| 842 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 843 | public void toggleMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 844 | presenter.clickOnGoingPane(); |
| 845 | } |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 846 | |
| 847 | private void setLoading(boolean isLoading) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 848 | if (binding == null) |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 849 | return; |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 850 | if (isLoading) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 851 | binding.btnTakePicture.setVisibility(View.GONE); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 852 | binding.pbDataTransfer.setVisibility(View.VISIBLE); |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 853 | } else { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 854 | binding.btnTakePicture.setVisibility(View.VISIBLE); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 855 | binding.pbDataTransfer.setVisibility(View.GONE); |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 856 | } |
| 857 | } |
Adrien Béraud | 1b8ac9f | 2018-05-31 14:34:23 -0400 | [diff] [blame] | 858 | |
Adrien Béraud | ae45ffa | 2018-07-06 16:21:29 -0400 | [diff] [blame] | 859 | public void handleShareIntent(Intent intent) { |
| 860 | String type = intent.getType(); |
| 861 | if (type == null) { |
| 862 | Log.w(TAG, "Can't share with no type"); |
| 863 | return; |
| 864 | } |
Rayan Osseiran | e445027 | 2019-06-03 14:17:19 -0400 | [diff] [blame] | 865 | if (type.startsWith("text/plain")) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 866 | binding.msgInputTxt.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); |
Rayan Osseiran | e445027 | 2019-06-03 14:17:19 -0400 | [diff] [blame] | 867 | } else { |
Adrien Béraud | ae45ffa | 2018-07-06 16:21:29 -0400 | [diff] [blame] | 868 | android.net.Uri uri = intent.getData(); |
| 869 | ClipData clip = intent.getClipData(); |
| 870 | if (uri == null && clip != null && clip.getItemCount() > 0) |
| 871 | uri = clip.getItemAt(0).getUri(); |
| 872 | if (uri == null) |
| 873 | return; |
Adrien Béraud | 1af6c01 | 2019-05-25 23:20:29 -0400 | [diff] [blame] | 874 | startFileSend(AndroidFileUtils.getCacheFile(requireContext(), uri).flatMapCompletable(this::sendFile)); |
Adrien Béraud | ae45ffa | 2018-07-06 16:21:29 -0400 | [diff] [blame] | 875 | } |
| 876 | } |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 877 | |
| 878 | /** |
| 879 | * Creates an intent using Android Storage Access Framework |
| 880 | * This intent is then received by applications that can handle it like |
| 881 | * Downloads or Google drive |
| 882 | * @param file DataTransfer of the file that is going to be stored |
| 883 | * @param currentFileAbsolutePath absolute path of the file we want to save |
| 884 | */ |
| 885 | public void startSaveFile(DataTransfer file, String currentFileAbsolutePath){ |
| 886 | //Get the current file absolute path and store it |
| 887 | mCurrentFileAbsolutePath = currentFileAbsolutePath; |
| 888 | |
| 889 | //Use Android Storage File Access to download the file |
| 890 | Intent downloadFileIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT); |
| 891 | downloadFileIntent.setType(AndroidFileUtils.getMimeTypeFromExtension(file.getExtension())); |
| 892 | |
| 893 | downloadFileIntent.addCategory(Intent.CATEGORY_OPENABLE); |
| 894 | downloadFileIntent.putExtra(Intent.EXTRA_TITLE,file.getDisplayName()); |
| 895 | |
| 896 | startActivityForResult(downloadFileIntent, ConversationFragment.REQUEST_CODE_SAVE_FILE); |
| 897 | } |
| 898 | |
Adrien Béraud | e32ab74 | 2018-08-25 21:15:08 -0400 | [diff] [blame] | 899 | } |