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 | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 23 | import android.animation.LayoutTransition; |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 24 | import android.animation.ValueAnimator; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 25 | import android.annotation.SuppressLint; |
Adrien Béraud | 21a3ea2 | 2020-04-01 16:06:09 -0400 | [diff] [blame] | 26 | import android.app.Activity; |
Rayan Osseiran | e445027 | 2019-06-03 14:17:19 -0400 | [diff] [blame] | 27 | import android.content.ActivityNotFoundException; |
Adrien Béraud | ae45ffa | 2018-07-06 16:21:29 -0400 | [diff] [blame] | 28 | import android.content.ClipData; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 29 | import android.content.ComponentName; |
Adrien Béraud | 1b8ac9f | 2018-05-31 14:34:23 -0400 | [diff] [blame] | 30 | import android.content.Context; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 31 | import android.content.Intent; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 32 | import android.content.ServiceConnection; |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 34 | import android.content.pm.PackageManager; |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 35 | import android.graphics.Typeface; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 36 | import android.content.res.Resources; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 37 | import android.os.Bundle; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 38 | import android.os.IBinder; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 39 | import android.provider.MediaStore; |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 40 | import android.text.Editable; |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 41 | import android.text.TextUtils; |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 42 | import android.text.TextWatcher; |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 43 | import android.util.Log; |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 44 | import android.view.LayoutInflater; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 45 | import android.view.Menu; |
| 46 | import android.view.MenuInflater; |
| 47 | import android.view.MenuItem; |
| 48 | import android.view.View; |
| 49 | import android.view.ViewGroup; |
| 50 | import android.view.inputmethod.EditorInfo; |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 51 | import android.widget.ImageView; |
| 52 | import android.widget.RelativeLayout; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 53 | import android.widget.Spinner; |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 54 | import android.widget.TextView; |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 55 | import android.widget.Toast; |
| 56 | |
Rayan Osseiran | e445027 | 2019-06-03 14:17:19 -0400 | [diff] [blame] | 57 | import com.google.android.material.snackbar.Snackbar; |
| 58 | |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 59 | import androidx.annotation.NonNull; |
| 60 | import androidx.annotation.Nullable; |
| 61 | import androidx.appcompat.app.ActionBar; |
| 62 | import androidx.appcompat.app.AppCompatActivity; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 63 | import androidx.appcompat.view.menu.MenuBuilder; |
| 64 | import androidx.appcompat.view.menu.MenuPopupHelper; |
| 65 | import androidx.appcompat.widget.PopupMenu; |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 66 | import androidx.appcompat.widget.Toolbar; |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 67 | import androidx.core.view.ViewCompat; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 68 | import androidx.fragment.app.Fragment; |
| 69 | import androidx.fragment.app.FragmentManager; |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 70 | import androidx.recyclerview.widget.DefaultItemAnimator; |
| 71 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 72 | import java.io.File; |
| 73 | import java.io.IOException; |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 74 | import java.util.HashMap; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 75 | import java.util.List; |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 76 | import java.util.Map; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 77 | |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 78 | import cx.ring.BuildConfig; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 79 | import cx.ring.R; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 80 | import cx.ring.adapters.ConversationAdapter; |
| 81 | import cx.ring.adapters.NumberAdapter; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 82 | import cx.ring.application.JamiApplication; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 83 | import cx.ring.client.CallActivity; |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 84 | import cx.ring.client.ContactDetailsActivity; |
Aline Bonnet | 830c4c6 | 2016-12-27 14:02:02 -0500 | [diff] [blame] | 85 | import cx.ring.client.ConversationActivity; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 86 | import cx.ring.client.HomeActivity; |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 87 | import cx.ring.contacts.AvatarFactory; |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 88 | import cx.ring.conversation.ConversationPresenter; |
| 89 | import cx.ring.conversation.ConversationView; |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 90 | import cx.ring.databinding.FragConversationBinding; |
Adrien Béraud | 171ba36 | 2018-12-14 21:35:40 -0500 | [diff] [blame] | 91 | import cx.ring.interfaces.Colorable; |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 92 | import cx.ring.model.Account; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 93 | import cx.ring.model.CallContact; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 94 | import cx.ring.model.Conversation; |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 95 | import cx.ring.model.Interaction; |
Adrien Béraud | 2153329 | 2018-03-22 14:11:35 -0400 | [diff] [blame] | 96 | import cx.ring.model.DataTransfer; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 97 | import cx.ring.model.Phone; |
Adrien Béraud | a0226ff | 2019-11-21 15:24:42 -0500 | [diff] [blame] | 98 | import cx.ring.model.Error; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 99 | import cx.ring.model.Uri; |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 100 | import cx.ring.mvp.BaseSupportFragment; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 101 | import cx.ring.services.LocationSharingService; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 102 | import cx.ring.services.NotificationService; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 103 | import cx.ring.utils.ActionHelper; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 104 | import cx.ring.utils.AndroidFileUtils; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 105 | import cx.ring.utils.ContentUriHandler; |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 106 | import cx.ring.utils.DeviceUtils; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 107 | import cx.ring.utils.ConversationPath; |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 108 | import cx.ring.utils.MediaButtonsHelper; |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 109 | import cx.ring.views.AvatarDrawable; |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 110 | import io.reactivex.Completable; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 111 | import io.reactivex.Single; |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 112 | import io.reactivex.android.schedulers.AndroidSchedulers; |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 113 | import io.reactivex.disposables.CompositeDisposable; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 114 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 115 | import static android.app.Activity.RESULT_OK; |
| 116 | |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 117 | public class ConversationFragment extends BaseSupportFragment<ConversationPresenter> implements |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 118 | MediaButtonsHelper.MediaButtonsHelperCallback, |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 119 | ConversationView, SharedPreferences.OnSharedPreferenceChangeListener { |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 120 | private static final String TAG = ConversationFragment.class.getSimpleName(); |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 121 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 122 | public static final int REQ_ADD_CONTACT = 42; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 123 | |
Adrien Béraud | 6ac6363 | 2018-12-09 00:11:21 -0500 | [diff] [blame] | 124 | public static final String KEY_CONTACT_RING_ID = BuildConfig.APPLICATION_ID + ".CONTACT_RING_ID"; |
| 125 | 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] | 126 | public static final String KEY_PREFERENCE_PENDING_MESSAGE = "pendingMessage"; |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 127 | public static final String KEY_PREFERENCE_CONVERSATION_COLOR = "color"; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 128 | public static final String EXTRA_SHOW_MAP = "showMap"; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 129 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 130 | private static final int REQUEST_CODE_FILE_PICKER = 1000; |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 131 | private static final int REQUEST_PERMISSION_CAMERA = 1001; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 132 | private static final int REQUEST_CODE_TAKE_PICTURE = 1002; |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 133 | private static final int REQUEST_CODE_SAVE_FILE = 1003; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 134 | private static final int REQUEST_CODE_CAPTURE_AUDIO = 1004; |
| 135 | private static final int REQUEST_CODE_CAPTURE_VIDEO = 1005; |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 136 | |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 137 | private ServiceConnection locationServiceConnection = null; |
| 138 | |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 139 | private FragConversationBinding binding; |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 140 | private MenuItem mAudioCallBtn = null; |
| 141 | private MenuItem mVideoCallBtn = null; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 142 | |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 143 | private View currentBottomView = null; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 144 | private ConversationAdapter mAdapter = null; |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 145 | private int marginPx; |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 146 | private int marginPxTotal; |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 147 | private final ValueAnimator animation = new ValueAnimator(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 148 | |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 149 | private SharedPreferences mPreferences; |
| 150 | |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 151 | private File mCurrentPhoto = null; |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 152 | private String mCurrentFileAbsolutePath = null; |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 153 | private final CompositeDisposable mCompositeDisposable = new CompositeDisposable(); |
Adrien Béraud | 742d320 | 2019-11-15 14:28:59 -0500 | [diff] [blame] | 154 | private int mSelectedPosition; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 155 | |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 156 | private AvatarDrawable mConversationAvatar; |
Adrien Béraud | 263cd5c | 2020-03-13 13:36:57 -0400 | [diff] [blame] | 157 | private final Map<String, AvatarDrawable> mParticipantAvatars = new HashMap<>(); |
| 158 | private final Map<String, AvatarDrawable> mSmallParticipantAvatars = new HashMap<>(); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 159 | private int mapWidth, mapHeight; |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 160 | |
| 161 | public AvatarDrawable getConversationAvatar(String uri) { |
| 162 | return mParticipantAvatars.get(uri); |
| 163 | } |
Adrien Béraud | 263cd5c | 2020-03-13 13:36:57 -0400 | [diff] [blame] | 164 | public AvatarDrawable getSmallConversationAvatar(String uri) { |
| 165 | synchronized (mSmallParticipantAvatars) { |
| 166 | return mSmallParticipantAvatars.get(uri); |
| 167 | } |
| 168 | } |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 169 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 170 | private static int getIndex(Spinner spinner, Uri myString) { |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 171 | for (int i = 0, n = spinner.getCount(); i < n; i++) |
| 172 | if (((Phone) spinner.getItemAtPosition(i)).getNumber().equals(myString)) { |
| 173 | return i; |
| 174 | } |
| 175 | return 0; |
| 176 | } |
| 177 | |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 178 | @Override |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 179 | public void refreshView(final List<Interaction> conversation) { |
Adrien Béraud | 20d4221 | 2018-03-02 14:40:38 -0500 | [diff] [blame] | 180 | if (conversation == null) { |
| 181 | return; |
| 182 | } |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 183 | if (binding != null) |
| 184 | binding.pbLoading.setVisibility(View.GONE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 185 | if (mAdapter != null) { |
| 186 | mAdapter.updateDataset(conversation); |
| 187 | } |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 188 | requireActivity().invalidateOptionsMenu(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 189 | } |
| 190 | |
Aline Bonnet | e8e87f6 | 2016-12-26 10:54:37 -0500 | [diff] [blame] | 191 | @Override |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 192 | public void scrollToEnd() { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 193 | if (mAdapter.getItemCount() > 0) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 194 | binding.histList.scrollToPosition(mAdapter.getItemCount() - 1); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 195 | } |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 198 | private static void setBottomPadding(@NonNull View view, int padding) { |
| 199 | view.setPadding( |
| 200 | view.getPaddingLeft(), |
| 201 | view.getPaddingTop(), |
| 202 | view.getPaddingRight(), |
| 203 | padding); |
| 204 | } |
| 205 | |
| 206 | private void updateListPadding() { |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 207 | if (currentBottomView != null && currentBottomView.getHeight() != 0) { |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 208 | setBottomPadding(binding.histList, currentBottomView.getHeight() + marginPxTotal); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 209 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) binding.mapCard.getLayoutParams(); |
| 210 | params.bottomMargin = currentBottomView.getHeight() + marginPxTotal; |
| 211 | binding.mapCard.setLayoutParams(params); |
| 212 | } |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 215 | @Nullable |
| 216 | @Override |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 217 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
Adrien Béraud | 7307cd5 | 2020-04-13 23:29:11 -0400 | [diff] [blame] | 218 | ((JamiApplication) getActivity().getApplication()).getInjectionComponent().inject(this); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 219 | Resources res = getResources(); |
| 220 | marginPx = res.getDimensionPixelSize(R.dimen.conversation_message_input_margin); |
| 221 | mapWidth = res.getDimensionPixelSize(R.dimen.location_sharing_minmap_width); |
| 222 | mapHeight = res.getDimensionPixelSize(R.dimen.location_sharing_minmap_height); |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 223 | marginPxTotal = marginPx; |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 224 | |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 225 | binding = FragConversationBinding.inflate(inflater, container, false); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 226 | binding.setPresenter(this); |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 227 | |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 228 | animation.setDuration(150); |
| 229 | animation.addUpdateListener(valueAnimator -> setBottomPadding(binding.histList, (Integer)valueAnimator.getAnimatedValue())); |
| 230 | |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 231 | ViewCompat.setOnApplyWindowInsetsListener(binding.histList, (v, insets) -> { |
| 232 | marginPxTotal = marginPx + insets.getSystemWindowInsetBottom(); |
| 233 | updateListPadding(); |
| 234 | insets.consumeSystemWindowInsets(); |
| 235 | return insets; |
| 236 | }); |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 237 | View layout = binding.conversationLayout; |
| 238 | |
| 239 | // remove action bar height for tablet layout |
| 240 | if (DeviceUtils.isTablet(getContext())) { |
| 241 | layout.setPadding(layout.getPaddingLeft(), 0, layout.getPaddingRight(), layout.getPaddingBottom()); |
| 242 | } |
| 243 | |
| 244 | int paddingTop = layout.getPaddingTop(); |
| 245 | ViewCompat.setOnApplyWindowInsetsListener(layout, (v, insets) -> { |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 246 | v.setPadding( |
| 247 | v.getPaddingLeft(), |
| 248 | paddingTop + insets.getSystemWindowInsetTop(), |
| 249 | v.getPaddingRight(), |
| 250 | v.getPaddingBottom()); |
| 251 | insets.consumeSystemWindowInsets(); |
| 252 | return insets; |
| 253 | }); |
| 254 | |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 255 | binding.ongoingcallPane.setVisibility(View.GONE); |
Adrien Béraud | 1af6c01 | 2019-05-25 23:20:29 -0400 | [diff] [blame] | 256 | binding.msgInputTxt.setMediaListener(contentInfo -> startFileSend(AndroidFileUtils |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 257 | .getCacheFile(requireContext(), contentInfo.getContentUri()) |
| 258 | .flatMapCompletable(this::sendFile) |
| 259 | .doFinally(contentInfo::releasePermission))); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 260 | binding.msgInputTxt.setOnEditorActionListener((v, actionId, event) -> actionSendMsgText(actionId)); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 261 | binding.msgInputTxt.setOnFocusChangeListener((view, hasFocus) -> { |
| 262 | if (hasFocus) { |
| 263 | Fragment fragment = getChildFragmentManager().findFragmentById(R.id.mapLayout); |
| 264 | if (fragment != null) { |
| 265 | ((LocationSharingFragment) fragment).hideControls(); |
| 266 | } |
| 267 | } |
| 268 | }); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 269 | binding.msgInputTxt.addTextChangedListener(new TextWatcher() { |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 270 | @Override |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 271 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 272 | } |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 273 | |
| 274 | @Override |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 275 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 276 | } |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 277 | |
| 278 | @Override |
| 279 | public void afterTextChanged(Editable s) { |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 280 | String message = s.toString(); |
Adrien Béraud | e09dd01 | 2019-11-15 14:57:18 -0500 | [diff] [blame] | 281 | boolean hasMessage = !TextUtils.isEmpty(message); |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 282 | presenter.onComposingChanged(hasMessage); |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 283 | if (hasMessage) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 284 | binding.msgSend.setVisibility(View.VISIBLE); |
| 285 | binding.emojiSend.setVisibility(View.GONE); |
Adrien Béraud | e09dd01 | 2019-11-15 14:57:18 -0500 | [diff] [blame] | 286 | } else { |
| 287 | binding.msgSend.setVisibility(View.GONE); |
| 288 | binding.emojiSend.setVisibility(View.VISIBLE); |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 289 | } |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 290 | if (mPreferences != null) { |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 291 | if (hasMessage) |
| 292 | mPreferences.edit().putString(KEY_PREFERENCE_PENDING_MESSAGE, message).apply(); |
| 293 | else |
| 294 | mPreferences.edit().remove(KEY_PREFERENCE_PENDING_MESSAGE).apply(); |
Adrien Béraud | 3a875a0 | 2018-07-18 17:54:17 -0400 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | }); |
Adrien Béraud | 9d4a81f | 2018-07-09 01:19:52 -0400 | [diff] [blame] | 298 | |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 299 | setHasOptionsMenu(true); |
| 300 | return binding.getRoot(); |
| 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { |
| 305 | super.onViewCreated(view, savedInstanceState); |
| 306 | |
| 307 | if (mPreferences != null) { |
| 308 | String pendingMessage = mPreferences.getString(KEY_PREFERENCE_PENDING_MESSAGE, null); |
| 309 | if (!TextUtils.isEmpty(pendingMessage)) { |
| 310 | binding.msgInputTxt.setText(pendingMessage); |
| 311 | binding.msgSend.setVisibility(View.VISIBLE); |
| 312 | binding.emojiSend.setVisibility(View.GONE); |
| 313 | } |
| 314 | } |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 315 | |
| 316 | 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] | 317 | if (oldBottom == 0 && oldTop == 0) { |
| 318 | updateListPadding(); |
| 319 | } else { |
| 320 | if (animation.isStarted()) |
| 321 | animation.cancel(); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 322 | animation.setIntValues(binding.histList.getPaddingBottom(), (currentBottomView == null ? 0 : currentBottomView.getHeight()) + marginPxTotal); |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 323 | animation.start(); |
| 324 | } |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 325 | }); |
| 326 | |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 327 | DefaultItemAnimator animator = (DefaultItemAnimator) binding.histList.getItemAnimator(); |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 328 | if (animator != null) |
| 329 | animator.setSupportsChangeAnimations(false); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 330 | binding.histList.setAdapter(mAdapter); |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 331 | } |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 332 | |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 333 | @Override |
| 334 | public void setConversationColor(int color) { |
Adrien Béraud | 171ba36 | 2018-12-14 21:35:40 -0500 | [diff] [blame] | 335 | Colorable activity = (Colorable) getActivity(); |
| 336 | if (activity != null) |
| 337 | activity.setColor(color); |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 338 | mAdapter.setPrimaryColor(color); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Adrien Béraud | 7c50511 | 2018-03-20 16:03:28 -0400 | [diff] [blame] | 341 | @Override |
Adrien Béraud | 4030d2e | 2018-12-02 23:08:03 -0500 | [diff] [blame] | 342 | public void onDestroyView() { |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 343 | if (mPreferences != null) |
| 344 | mPreferences.unregisterOnSharedPreferenceChangeListener(this); |
Adrien Béraud | 772e216 | 2019-02-12 16:00:21 -0500 | [diff] [blame] | 345 | animation.removeAllUpdateListeners(); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 346 | binding.histList.setAdapter(null); |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 347 | mCompositeDisposable.clear(); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 348 | if (locationServiceConnection != null) { |
| 349 | try { |
| 350 | requireContext().unbindService(locationServiceConnection); |
| 351 | } catch (Exception e) { |
| 352 | Log.w(TAG, "Error unbinding service: " + e.getMessage()); |
| 353 | } |
| 354 | } |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 355 | mAdapter = null; |
Adrien Béraud | 4030d2e | 2018-12-02 23:08:03 -0500 | [diff] [blame] | 356 | super.onDestroyView(); |
Adrien Béraud | c35f7f4 | 2020-04-15 15:29:29 -0400 | [diff] [blame] | 357 | binding = null; |
Adrien Béraud | 4030d2e | 2018-12-02 23:08:03 -0500 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | @Override |
Adrien Béraud | fd08367 | 2019-10-31 13:52:38 -0400 | [diff] [blame] | 361 | public boolean onContextItemSelected(@NonNull MenuItem item) { |
Adrien Béraud | 7c50511 | 2018-03-20 16:03:28 -0400 | [diff] [blame] | 362 | if (mAdapter.onContextItemSelected(item)) |
| 363 | return true; |
| 364 | return super.onContextItemSelected(item); |
| 365 | } |
| 366 | |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 367 | public void updateAdapterItem() { |
Adrien Béraud | 742d320 | 2019-11-15 14:28:59 -0500 | [diff] [blame] | 368 | if (mSelectedPosition != -1) { |
| 369 | mAdapter.notifyItemChanged(mSelectedPosition); |
| 370 | mSelectedPosition = -1; |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Alexandre Lision | 66a9f9a | 2017-02-26 20:28:27 -0500 | [diff] [blame] | 374 | public void sendMessageText() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 375 | String message = binding.msgInputTxt.getText().toString(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 376 | clearMsgEdit(); |
| 377 | presenter.sendTextMessage(message); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 378 | } |
| 379 | |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 380 | public void sendEmoji() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 381 | presenter.sendTextMessage(binding.emojiSend.getText().toString()); |
Adrien Béraud | 58bd92b | 2018-08-23 10:54:25 -0400 | [diff] [blame] | 382 | } |
| 383 | |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 384 | @SuppressLint("RestrictedApi") |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 385 | public void expandMenu(View v) { |
| 386 | Context context = requireContext(); |
| 387 | PopupMenu popup = new PopupMenu(context, v); |
| 388 | popup.inflate(R.menu.conversation_share_actions); |
| 389 | popup.setOnMenuItemClickListener(item -> { |
| 390 | switch(item.getItemId()) { |
Adrien Béraud | d5637f2 | 2020-05-14 12:41:50 -0400 | [diff] [blame^] | 391 | case R.id.conv_send_audio: |
| 392 | sendAudioMessage(); |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 393 | break; |
Adrien Béraud | d5637f2 | 2020-05-14 12:41:50 -0400 | [diff] [blame^] | 394 | case R.id.conv_send_video: |
| 395 | sendVideoMessage(); |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 396 | break; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 397 | case R.id.conv_send_file: |
Adrien Béraud | c35f7f4 | 2020-04-15 15:29:29 -0400 | [diff] [blame] | 398 | presenter.selectFile(); |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 399 | break; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 400 | case R.id.conv_share_location: |
| 401 | shareLocation(); |
| 402 | break; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 403 | } |
| 404 | return false; |
| 405 | }); |
| 406 | MenuPopupHelper menuHelper = new MenuPopupHelper(context, (MenuBuilder) popup.getMenu(), v); |
| 407 | menuHelper.setForceShowIcon(true); |
| 408 | menuHelper.show(); |
| 409 | } |
| 410 | |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 411 | public void shareLocation() { |
| 412 | presenter.shareLocation(); |
| 413 | } |
| 414 | |
| 415 | public void closeLocationSharing(boolean isSharing) { |
| 416 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) binding.mapCard.getLayoutParams(); |
| 417 | if (params.width != mapWidth) { |
| 418 | params.width = mapWidth; |
| 419 | params.height = mapHeight; |
| 420 | binding.mapCard.setLayoutParams(params); |
| 421 | } |
| 422 | if (!isSharing) |
| 423 | hideMap(); |
| 424 | } |
| 425 | |
| 426 | public void openLocationSharing() { |
| 427 | binding.conversationLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING); |
| 428 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) binding.mapCard.getLayoutParams(); |
| 429 | if (params.width != ViewGroup.LayoutParams.MATCH_PARENT) { |
| 430 | params.width = ViewGroup.LayoutParams.MATCH_PARENT; |
| 431 | params.height = ViewGroup.LayoutParams.MATCH_PARENT; |
| 432 | binding.mapCard.setLayoutParams(params); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | @Override |
| 437 | public void startShareLocation(String accountId, String conversationId) { |
| 438 | showMap(accountId, conversationId, true); |
| 439 | } |
| 440 | |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 441 | /** |
| 442 | * Used to update with the past adapter position when a long click was registered |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 443 | */ |
| 444 | public void updatePosition(int position) { |
Adrien Béraud | 742d320 | 2019-11-15 14:28:59 -0500 | [diff] [blame] | 445 | mSelectedPosition = position; |
Rayan Osseiran | e634a56 | 2019-05-29 13:44:55 -0400 | [diff] [blame] | 446 | } |
| 447 | |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 448 | @Override |
| 449 | public void showMap(String accountId, String contactId, boolean open) { |
| 450 | if (binding.mapCard.getVisibility() == View.GONE) { |
| 451 | Log.w(TAG, "showMap " + accountId + " " + contactId); |
| 452 | |
| 453 | FragmentManager fragmentManager = getChildFragmentManager(); |
| 454 | LocationSharingFragment fragment = LocationSharingFragment.newInstance(accountId, contactId, open); |
| 455 | fragmentManager.beginTransaction() |
| 456 | .add(R.id.mapLayout, fragment, "map") |
| 457 | .commit(); |
| 458 | binding.mapCard.setVisibility(View.VISIBLE); |
| 459 | } |
| 460 | if (open) { |
| 461 | Fragment fragment = getChildFragmentManager().findFragmentById(R.id.mapLayout); |
| 462 | if (fragment != null) { |
| 463 | ((LocationSharingFragment) fragment).showControls(); |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | @Override |
| 469 | public void hideMap() { |
| 470 | if (binding.mapCard.getVisibility() != View.GONE) { |
| 471 | binding.mapCard.setVisibility(View.GONE); |
| 472 | |
| 473 | FragmentManager fragmentManager = getChildFragmentManager(); |
| 474 | Fragment fragment = fragmentManager.findFragmentById(R.id.mapLayout); |
| 475 | |
| 476 | if (fragment != null) { |
| 477 | fragmentManager.beginTransaction() |
| 478 | .remove(fragment) |
| 479 | .commit(); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
Adrien Béraud | d5637f2 | 2020-05-14 12:41:50 -0400 | [diff] [blame^] | 484 | public void sendAudioMessage() { |
| 485 | if (!presenter.getDeviceRuntimeService().hasAudioPermission()) { |
| 486 | requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, REQUEST_CODE_CAPTURE_AUDIO); |
| 487 | } else { |
| 488 | Context ctx = requireContext(); |
| 489 | Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); |
| 490 | |
| 491 | if (intent.resolveActivity(ctx.getPackageManager()) != null) { |
| 492 | try { |
| 493 | mCurrentPhoto = AndroidFileUtils.createAudioFile(ctx); |
| 494 | } catch (IOException ex) { |
| 495 | Log.e(TAG, "takePicture: error creating temporary file", ex); |
| 496 | return; |
| 497 | } |
| 498 | startActivityForResult(intent, REQUEST_CODE_CAPTURE_AUDIO); |
| 499 | } else { |
| 500 | Toast.makeText(getActivity(), "Can't find audio recorder app", Toast.LENGTH_SHORT).show(); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | public void sendVideoMessage() { |
| 506 | if (!presenter.getDeviceRuntimeService().hasVideoPermission()) { |
| 507 | requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_CODE_CAPTURE_VIDEO); |
| 508 | } else { |
| 509 | Context context = requireContext(); |
| 510 | Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); |
| 511 | intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); |
| 512 | intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1); |
| 513 | intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true); |
| 514 | if (intent.resolveActivity(context.getPackageManager()) != null) { |
| 515 | try { |
| 516 | mCurrentPhoto = AndroidFileUtils.createVideoFile(context); |
| 517 | } catch (IOException ex) { |
| 518 | Log.e(TAG, "takePicture: error creating temporary file", ex); |
| 519 | return; |
| 520 | } |
| 521 | intent.putExtra(MediaStore.EXTRA_OUTPUT, ContentUriHandler.getUriForFile(context, ContentUriHandler.AUTHORITY_FILES, mCurrentPhoto)); |
| 522 | startActivityForResult(intent, REQUEST_CODE_CAPTURE_VIDEO); |
| 523 | } else { |
| 524 | Toast.makeText(getActivity(), "Can't find video recorder app", Toast.LENGTH_SHORT).show(); |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 529 | public void takePicture() { |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 530 | if (!presenter.getDeviceRuntimeService().hasVideoPermission()) { |
Adrien Béraud | d5637f2 | 2020-05-14 12:41:50 -0400 | [diff] [blame^] | 531 | requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_CODE_TAKE_PICTURE); |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 532 | } else { |
Adrien Béraud | f5c32f9 | 2019-01-03 23:40:00 -0500 | [diff] [blame] | 533 | Context c = getContext(); |
| 534 | if (c == null) |
| 535 | return; |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 536 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
Adrien Béraud | f5c32f9 | 2019-01-03 23:40:00 -0500 | [diff] [blame] | 537 | if (takePictureIntent.resolveActivity(c.getPackageManager()) != null) { |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 538 | // Create the File where the photo should go |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 539 | try { |
Adrien Béraud | 20df00c | 2020-05-01 19:35:10 -0400 | [diff] [blame] | 540 | File photoFile = AndroidFileUtils.createImageFile(c); |
| 541 | Log.i(TAG, "takePicture: trying to save to " + photoFile); |
| 542 | android.net.Uri photoURI = ContentUriHandler.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, photoFile); |
| 543 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI) |
| 544 | .putExtra("android.intent.extras.CAMERA_FACING", 1) |
| 545 | .putExtra("android.intent.extras.LENS_FACING_FRONT", 1) |
| 546 | .putExtra("android.intent.extra.USE_FRONT_CAMERA", true); |
| 547 | mCurrentPhoto = photoFile; |
| 548 | startActivityForResult(takePictureIntent, REQUEST_CODE_TAKE_PICTURE); |
| 549 | } catch (Exception e) { |
| 550 | Toast.makeText(c, "Error taking picture: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 551 | } |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 552 | } |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 556 | @Override |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 557 | public void askWriteExternalStoragePermission() { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 558 | requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, JamiApplication.PERMISSIONS_REQUEST); |
Pierre Duchemin | 4af6b39 | 2018-02-02 11:23:56 -0500 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | @Override |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 562 | public void openFilePicker() { |
| 563 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); |
| 564 | intent.addCategory(Intent.CATEGORY_OPENABLE); |
| 565 | intent.setType("*/*"); |
| 566 | |
| 567 | startActivityForResult(intent, REQUEST_CODE_FILE_PICKER); |
| 568 | } |
| 569 | |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 570 | private Completable sendFile(File file) { |
| 571 | return Completable.fromAction(() -> presenter.sendFile(file)); |
| 572 | } |
| 573 | |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 574 | private void startFileSend(Completable op) { |
| 575 | setLoading(true); |
Adrien Béraud | 1af6c01 | 2019-05-25 23:20:29 -0400 | [diff] [blame] | 576 | op.observeOn(AndroidSchedulers.mainThread()) |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 577 | .doFinally(() -> setLoading(false)) |
| 578 | .subscribe(() -> {}, e -> { |
| 579 | Log.e(TAG, "startFileSend: not able to create cache file", e); |
Adrien Béraud | a0226ff | 2019-11-21 15:24:42 -0500 | [diff] [blame] | 580 | displayErrorToast(Error.INVALID_FILE); |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 581 | }); |
| 582 | } |
| 583 | |
Pierre Duchemin | e0c3a49 | 2018-02-01 16:22:45 -0500 | [diff] [blame] | 584 | @Override |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 585 | public void onActivityResult(int requestCode, int resultCode, Intent resultData) { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 586 | Log.w(TAG, "onActivityResult: " + requestCode + " " + resultCode + " " + resultData); |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 587 | super.onActivityResult(requestCode, resultCode, resultData); |
| 588 | |
| 589 | if (requestCode == REQUEST_CODE_FILE_PICKER && resultCode == RESULT_OK) { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 590 | if (resultData == null) { |
| 591 | return; |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 592 | } |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 593 | android.net.Uri uri = resultData.getData(); |
| 594 | if (uri == null) { |
| 595 | return; |
| 596 | } |
Adrien Béraud | 1af6c01 | 2019-05-25 23:20:29 -0400 | [diff] [blame] | 597 | startFileSend(AndroidFileUtils.getCacheFile(requireContext(), uri) |
| 598 | .observeOn(AndroidSchedulers.mainThread()) |
| 599 | .flatMapCompletable(this::sendFile)); |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 600 | } else if (requestCode == REQUEST_CODE_TAKE_PICTURE |
| 601 | || requestCode == REQUEST_CODE_CAPTURE_AUDIO |
| 602 | || requestCode == REQUEST_CODE_CAPTURE_VIDEO) { |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 603 | if (resultCode != RESULT_OK) { |
| 604 | mCurrentPhoto = null; |
| 605 | return; |
| 606 | } |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 607 | Log.w(TAG, "onActivityResult: mCurrentPhoto " + mCurrentPhoto.getAbsolutePath() + " " + mCurrentPhoto.exists() + " " + mCurrentPhoto.length()); |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 608 | Single<File> file = null; |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 609 | if (mCurrentPhoto == null || !mCurrentPhoto.exists() || mCurrentPhoto.length() == 0) { |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 610 | android.net.Uri createdUri = resultData.getData(); |
| 611 | if (createdUri != null) { |
| 612 | file = AndroidFileUtils.getCacheFile(requireContext(), createdUri); |
| 613 | } |
| 614 | } else { |
| 615 | file = Single.just(mCurrentPhoto); |
Adrien Béraud | 6453872 | 2018-03-15 17:34:00 -0400 | [diff] [blame] | 616 | } |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 617 | mCurrentPhoto = null; |
Adrien Béraud | 898c2bf | 2019-09-26 14:49:33 -0400 | [diff] [blame] | 618 | if (file == null) { |
| 619 | Toast.makeText(getActivity(), "Can't find picture", Toast.LENGTH_SHORT).show(); |
| 620 | return; |
| 621 | } |
| 622 | startFileSend(file.flatMapCompletable(this::sendFile)); |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 623 | } |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 624 | // File download trough SAF |
| 625 | else if(requestCode == ConversationFragment.REQUEST_CODE_SAVE_FILE |
| 626 | && resultCode == RESULT_OK){ |
| 627 | if(resultData != null && resultData.getData() != null ) { |
| 628 | //Get the Uri of the file that was created by the app that received our intent |
| 629 | android.net.Uri createdUri = resultData.getData(); |
| 630 | |
| 631 | //Try to copy the data of the current file into the newly created one |
| 632 | File input = new File(mCurrentFileAbsolutePath); |
| 633 | if(requireContext().getContentResolver() != null) |
Adrien Béraud | d5637f2 | 2020-05-14 12:41:50 -0400 | [diff] [blame^] | 634 | mCompositeDisposable.add(AndroidFileUtils.copyFileToUri(requireContext().getContentResolver(), input, createdUri). |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 635 | observeOn(AndroidSchedulers.mainThread()). |
Adrien Béraud | d5637f2 | 2020-05-14 12:41:50 -0400 | [diff] [blame^] | 636 | subscribe(()-> Toast.makeText(getContext(), R.string.file_saved_successfully, Toast.LENGTH_SHORT).show(), |
| 637 | error-> Toast.makeText(getContext(), R.string.generic_error, Toast.LENGTH_SHORT).show())); |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 638 | |
| 639 | } |
| 640 | } |
| 641 | |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | @Override |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 645 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 646 | for (int i = 0, n = permissions.length; i < n; i++) { |
Adrien Béraud | d5637f2 | 2020-05-14 12:41:50 -0400 | [diff] [blame^] | 647 | boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED; |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 648 | switch (permissions[i]) { |
| 649 | case Manifest.permission.CAMERA: |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 650 | presenter.cameraPermissionChanged(granted); |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 651 | if (granted) { |
Adrien Béraud | d5637f2 | 2020-05-14 12:41:50 -0400 | [diff] [blame^] | 652 | if (requestCode == REQUEST_CODE_CAPTURE_VIDEO) { |
| 653 | sendVideoMessage(); |
| 654 | } else if (requestCode == REQUEST_CODE_TAKE_PICTURE) { |
| 655 | takePicture(); |
| 656 | } |
| 657 | } |
| 658 | return; |
| 659 | case Manifest.permission.RECORD_AUDIO: |
| 660 | if (granted) { |
| 661 | if (requestCode == REQUEST_CODE_CAPTURE_AUDIO) { |
| 662 | sendAudioMessage(); |
| 663 | } |
Adrien Béraud | 4f542f9 | 2019-01-03 12:17:53 -0500 | [diff] [blame] | 664 | } |
| 665 | return; |
| 666 | default: |
| 667 | break; |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | @Override |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 673 | public void addElement(Interaction element) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 674 | mAdapter.add(element); |
| 675 | scrollToEnd(); |
| 676 | } |
Adrien Béraud | 3cbc7fa | 2018-07-18 18:36:21 -0400 | [diff] [blame] | 677 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 678 | @Override |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 679 | public void updateElement(Interaction element) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 680 | mAdapter.update(element); |
| 681 | } |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 682 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 683 | @Override |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 684 | public void removeElement(Interaction element) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 685 | mAdapter.remove(element); |
Adrien Béraud | 2153329 | 2018-03-22 14:11:35 -0400 | [diff] [blame] | 686 | } |
| 687 | |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 688 | @Override |
Adrien Béraud | fd458ea | 2020-02-28 13:40:18 -0500 | [diff] [blame] | 689 | public void setComposingStatus(Account.ComposingStatus composingStatus) { |
| 690 | mAdapter.setComposingStatus(composingStatus); |
| 691 | if (composingStatus == Account.ComposingStatus.Active) |
| 692 | scrollToEnd(); |
| 693 | } |
| 694 | |
| 695 | @Override |
Adrien Béraud | 263cd5c | 2020-03-13 13:36:57 -0400 | [diff] [blame] | 696 | public void setLastDisplayed(Interaction interaction) { |
| 697 | mAdapter.setLastDisplayed(interaction); |
| 698 | } |
| 699 | |
| 700 | @Override |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 701 | public void shareFile(File path) { |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 702 | Context c = getContext(); |
| 703 | if (c == null) |
| 704 | return; |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 705 | android.net.Uri fileUri = null; |
| 706 | try { |
Andreas Traczyk | bc5d235 | 2020-01-23 14:27:59 -0500 | [diff] [blame] | 707 | fileUri = ContentUriHandler.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, path); |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 708 | } catch (IllegalArgumentException e) { |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 709 | 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] | 710 | } |
| 711 | if (fileUri != null) { |
| 712 | Intent sendIntent = new Intent(); |
| 713 | sendIntent.setAction(Intent.ACTION_SEND); |
| 714 | sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 715 | String type = c.getContentResolver().getType(fileUri); |
Adrien Béraud | fcf457f | 2018-04-03 17:46:34 -0400 | [diff] [blame] | 716 | sendIntent.setDataAndType(fileUri, type); |
| 717 | sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); |
| 718 | startActivity(Intent.createChooser(sendIntent, null)); |
| 719 | } |
| 720 | } |
| 721 | |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 722 | @Override |
| 723 | public void openFile(File path) { |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 724 | Context c = getContext(); |
| 725 | if (c == null) |
| 726 | return; |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 727 | android.net.Uri fileUri = null; |
| 728 | try { |
Andreas Traczyk | bc5d235 | 2020-01-23 14:27:59 -0500 | [diff] [blame] | 729 | fileUri = ContentUriHandler.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, path); |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 730 | } catch (IllegalArgumentException e) { |
| 731 | Log.e("File Selector", "The selected file can't be shared: " + path.getName()); |
| 732 | } |
| 733 | if (fileUri != null) { |
| 734 | Intent sendIntent = new Intent(); |
| 735 | sendIntent.setAction(Intent.ACTION_VIEW); |
| 736 | sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Adrien Béraud | 5054953 | 2019-01-03 12:22:16 -0500 | [diff] [blame] | 737 | String type = c.getContentResolver().getType(fileUri); |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 738 | sendIntent.setDataAndType(fileUri, type); |
| 739 | sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); |
| 740 | //startActivity(Intent.createChooser(sendIntent, null)); |
Rayan Osseiran | e445027 | 2019-06-03 14:17:19 -0400 | [diff] [blame] | 741 | try { |
| 742 | startActivity(sendIntent); |
| 743 | } catch (ActivityNotFoundException e) { |
| 744 | Snackbar.make(getView(), R.string.conversation_open_file_error, Snackbar.LENGTH_LONG).show(); |
| 745 | Log.e("File Loader", "File of unknown type, could not open: " + path.getName()); |
| 746 | } |
Adrien Béraud | b2b3f44 | 2018-12-01 17:42:38 -0500 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 750 | boolean actionSendMsgText(int actionId) { |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 751 | switch (actionId) { |
| 752 | case EditorInfo.IME_ACTION_SEND: |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 753 | sendMessageText(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 754 | return true; |
| 755 | } |
| 756 | return false; |
| 757 | } |
| 758 | |
Alexandre Lision | 66a9f9a | 2017-02-26 20:28:27 -0500 | [diff] [blame] | 759 | public void onClick() { |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 760 | presenter.clickOnGoingPane(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | @Override |
| 764 | public void onPause() { |
| 765 | super.onPause(); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 766 | presenter.pause(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | @Override |
| 770 | public void onResume() { |
| 771 | super.onResume(); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 772 | presenter.resume(); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | @Override |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 776 | public void onDestroy() { |
| 777 | mCompositeDisposable.dispose(); |
| 778 | super.onDestroy(); |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | @Override |
Adrien Béraud | 263cd5c | 2020-03-13 13:36:57 -0400 | [diff] [blame] | 782 | public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { |
| 783 | if (!isVisible()) { |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 784 | return; |
| 785 | } |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 786 | inflater.inflate(R.menu.conversation_actions, menu); |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 787 | mAudioCallBtn = menu.findItem(R.id.conv_action_audiocall); |
| 788 | mVideoCallBtn = menu.findItem(R.id.conv_action_videocall); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | @Override |
| 792 | public boolean onOptionsItemSelected(MenuItem item) { |
| 793 | switch (item.getItemId()) { |
| 794 | case android.R.id.home: |
| 795 | startActivity(new Intent(getActivity(), HomeActivity.class)); |
| 796 | return true; |
| 797 | case R.id.conv_action_audiocall: |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 798 | presenter.goToCall(true); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 799 | return true; |
| 800 | case R.id.conv_action_videocall: |
Adrien Béraud | 4a64305 | 2019-11-18 12:41:23 -0500 | [diff] [blame] | 801 | presenter.goToCall(false); |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 802 | return true; |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 803 | case R.id.conv_contact_details: |
| 804 | presenter.openContact(); |
Aline Bonnet | 54cf69b | 2017-03-28 12:03:45 -0400 | [diff] [blame] | 805 | return true; |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 806 | default: |
| 807 | return super.onOptionsItemSelected(item); |
| 808 | } |
| 809 | } |
| 810 | |
Aline Bonnet | 9c6defe | 2016-12-21 13:21:02 -0500 | [diff] [blame] | 811 | @Override |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 812 | protected void initPresenter(ConversationPresenter presenter) { |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 813 | Bundle args = getArguments(); |
| 814 | if (args == null) |
| 815 | return; |
| 816 | Uri contactUri = new Uri(args.getString(KEY_CONTACT_RING_ID)); |
| 817 | String accountId = args.getString(KEY_ACCOUNT_ID); |
| 818 | mAdapter = new ConversationAdapter(this, presenter); |
| 819 | presenter.init(contactUri, accountId); |
Adrien Béraud | 56c3413 | 2018-11-29 13:32:00 -0500 | [diff] [blame] | 820 | try { |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 821 | mPreferences = requireActivity().getSharedPreferences(accountId + "_" + contactUri.getRawRingId(), Context.MODE_PRIVATE); |
Adrien Béraud | 3c483ce | 2019-01-02 17:33:49 -0500 | [diff] [blame] | 822 | mPreferences.registerOnSharedPreferenceChangeListener(this); |
| 823 | 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] | 824 | } catch (Exception e) { |
| 825 | Log.e(TAG, "Can't load conversation preferences"); |
| 826 | } |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 827 | |
| 828 | if (locationServiceConnection == null) { |
| 829 | locationServiceConnection = new ServiceConnection() { |
| 830 | @Override |
| 831 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 832 | Log.w(TAG, "onServiceConnected"); |
| 833 | LocationSharingService.LocalBinder binder = (LocationSharingService.LocalBinder) service; |
| 834 | LocationSharingService locationService = binder.getService(); |
| 835 | ConversationPath path = new ConversationPath(presenter.getPath()); |
| 836 | if (locationService.isSharing(path)) { |
| 837 | showMap(accountId, contactUri.getUri(), false); |
| 838 | } |
| 839 | try { |
| 840 | requireContext().unbindService(locationServiceConnection); |
| 841 | } catch (Exception e) { |
| 842 | Log.w(TAG, "Error unbinding service", e); |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | @Override |
| 847 | public void onServiceDisconnected(ComponentName name) { |
| 848 | Log.w(TAG, "onServiceDisconnected"); |
| 849 | locationServiceConnection = null; |
| 850 | } |
| 851 | }; |
| 852 | |
| 853 | Log.w(TAG, "bindService"); |
| 854 | requireContext().bindService(new Intent(requireContext(), LocationSharingService.class), locationServiceConnection, 0); |
| 855 | } |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | @Override |
| 859 | public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { |
| 860 | switch (key) { |
| 861 | case KEY_PREFERENCE_CONVERSATION_COLOR: |
| 862 | presenter.setConversationColor(prefs.getInt(KEY_PREFERENCE_CONVERSATION_COLOR, getResources().getColor(R.color.color_primary_light))); |
| 863 | break; |
| 864 | } |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | @Override |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 868 | public void displayContact(final CallContact contact) { |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 869 | mCompositeDisposable.clear(); |
| 870 | mCompositeDisposable.add(AvatarFactory.getAvatar(requireContext(), contact) |
| 871 | .doOnSuccess(d -> { |
| 872 | mConversationAvatar = (AvatarDrawable) d; |
| 873 | mParticipantAvatars.put(contact.getPrimaryNumber(), |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 874 | new AvatarDrawable((AvatarDrawable) d)); |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 875 | }) |
| 876 | .flatMapObservable(d -> contact.getUpdatesSubject()) |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 877 | .observeOn(AndroidSchedulers.mainThread()) |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 878 | .subscribe(c -> { |
| 879 | mConversationAvatar.update(c); |
| 880 | String uri = contact.getPrimaryNumber(); |
Adrien Béraud | 263cd5c | 2020-03-13 13:36:57 -0400 | [diff] [blame] | 881 | AvatarDrawable ad = mParticipantAvatars.get(uri); |
| 882 | if (ad != null) |
| 883 | ad.update(c); |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 884 | setupActionbar(contact); |
| 885 | mAdapter.setPhoto(); |
| 886 | })); |
Adrien Béraud | 263cd5c | 2020-03-13 13:36:57 -0400 | [diff] [blame] | 887 | mCompositeDisposable.add(AvatarFactory.getAvatar(requireContext(), contact, false) |
| 888 | .doOnSuccess(d -> mSmallParticipantAvatars.put(contact.getPrimaryNumber(), new AvatarDrawable((AvatarDrawable) d))) |
| 889 | .flatMapObservable(d -> contact.getUpdatesSubject()) |
| 890 | .subscribe(c -> { |
| 891 | synchronized (mSmallParticipantAvatars) { |
| 892 | String uri = contact.getPrimaryNumber(); |
| 893 | AvatarDrawable ad = mSmallParticipantAvatars.get(uri); |
| 894 | if (ad != null) |
| 895 | ad.update(c); |
| 896 | } |
| 897 | })); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | @Override |
| 901 | public void displayOnGoingCallPane(final boolean display) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 902 | binding.ongoingcallPane.setVisibility(display ? View.VISIBLE : View.GONE); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | @Override |
| 906 | public void displayNumberSpinner(final Conversation conversation, final Uri number) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 907 | binding.numberSelector.setVisibility(View.VISIBLE); |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 908 | binding.numberSelector.setAdapter(new NumberAdapter(getActivity(), |
| 909 | conversation.getContact(), false)); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 910 | binding.numberSelector.setSelection(getIndex(binding.numberSelector, number)); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | @Override |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 914 | public void hideNumberSpinner() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 915 | binding.numberSelector.setVisibility(View.GONE); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | @Override |
| 919 | public void clearMsgEdit() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 920 | binding.msgInputTxt.setText(""); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | @Override |
| 924 | public void goToHome() { |
| 925 | if (getActivity() instanceof ConversationActivity) { |
| 926 | getActivity().finish(); |
Aline Bonnet | eb5f7ff | 2017-01-17 11:09:17 -0500 | [diff] [blame] | 927 | } |
| 928 | } |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 929 | |
| 930 | @Override |
| 931 | public void goToAddContact(CallContact callContact) { |
| 932 | startActivityForResult(ActionHelper.getAddNumberIntentForContact(callContact), REQ_ADD_CONTACT); |
| 933 | } |
| 934 | |
| 935 | @Override |
| 936 | public void goToCallActivity(String conferenceId) { |
| 937 | startActivity(new Intent(Intent.ACTION_VIEW) |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 938 | .setClass(requireActivity().getApplicationContext(), CallActivity.class) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 939 | .putExtra(NotificationService.KEY_CALL_ID, conferenceId)); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | @Override |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 943 | public void goToContactActivity(String accountId, String contactRingId) { |
| 944 | 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] | 945 | .setClass(requireActivity().getApplicationContext(), ContactDetailsActivity.class)); |
Adrien Béraud | 0f3ee3d | 2018-12-08 22:03:54 -0500 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | @Override |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 949 | public void goToCallActivityWithResult(String accountId, String contactRingId, boolean audioOnly) { |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 950 | Intent intent = new Intent(CallActivity.ACTION_CALL) |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 951 | .setClass(requireActivity().getApplicationContext(), CallActivity.class) |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 952 | .putExtra(KEY_ACCOUNT_ID, accountId) |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 953 | .putExtra(CallFragment.KEY_AUDIO_ONLY, audioOnly) |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 954 | .putExtra(KEY_CONTACT_RING_ID, contactRingId); |
Hadrien De Sousa | ec95e5e | 2017-03-21 15:28:23 -0400 | [diff] [blame] | 955 | startActivityForResult(intent, HomeActivity.REQUEST_CODE_CALL); |
| 956 | } |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 957 | |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 958 | private void setupActionbar(CallContact contact) { |
Adrien Béraud | 21a3ea2 | 2020-04-01 16:06:09 -0400 | [diff] [blame] | 959 | if (!isVisible()) { |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 960 | return; |
| 961 | } |
| 962 | |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 963 | ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); |
| 964 | if (actionBar == null) { |
| 965 | return; |
| 966 | } |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 967 | |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 968 | Context context = actionBar.getThemedContext(); |
| 969 | String displayName = contact.getDisplayName(); |
| 970 | String identity = contact.getRingUsername(); |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 971 | |
Adrien Béraud | 21a3ea2 | 2020-04-01 16:06:09 -0400 | [diff] [blame] | 972 | Activity activity = getActivity(); |
| 973 | if (activity instanceof HomeActivity) { |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 974 | Toolbar toolbar = getActivity().findViewById(R.id.main_toolbar); |
| 975 | TextView title = toolbar.findViewById(R.id.contact_title); |
| 976 | TextView subtitle = toolbar.findViewById(R.id.contact_subtitle); |
| 977 | ImageView logo = toolbar.findViewById(R.id.contact_image); |
| 978 | |
Adrien Béraud | 21a3ea2 | 2020-04-01 16:06:09 -0400 | [diff] [blame] | 979 | if (!((HomeActivity) activity).isConversationSelected()) { |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 980 | title.setText(""); |
| 981 | subtitle.setText(""); |
| 982 | logo.setImageDrawable(null); |
Adrien Béraud | b96a7d9 | 2020-02-24 11:55:05 -0500 | [diff] [blame] | 983 | return; |
| 984 | } |
| 985 | |
| 986 | logo.setVisibility(View.VISIBLE); |
| 987 | title.setText(displayName); |
| 988 | title.setTextSize(15); |
| 989 | title.setTypeface(null, Typeface.NORMAL); |
| 990 | |
| 991 | if (identity != null && !identity.equals(displayName)) { |
| 992 | subtitle.setText(identity); |
| 993 | |
| 994 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) title.getLayoutParams(); |
| 995 | params.addRule(RelativeLayout.ALIGN_TOP, R.id.contact_image); |
| 996 | title.setLayoutParams(params); |
| 997 | } else { |
| 998 | subtitle.setText(""); |
| 999 | |
| 1000 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) title.getLayoutParams(); |
| 1001 | params.removeRule(RelativeLayout.ALIGN_TOP); |
| 1002 | params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); |
| 1003 | title.setLayoutParams(params); |
| 1004 | } |
| 1005 | |
| 1006 | logo.setImageDrawable(mConversationAvatar); |
| 1007 | } else { |
| 1008 | if (identity != null && !identity.equals(displayName)) { |
| 1009 | actionBar.setSubtitle(identity); |
| 1010 | } |
| 1011 | actionBar.setTitle(displayName); |
| 1012 | int targetSize = (int) (AvatarFactory.SIZE_AB * context.getResources().getDisplayMetrics().density); |
| 1013 | mConversationAvatar.setInSize(targetSize); |
| 1014 | actionBar.setLogo(null); |
| 1015 | actionBar.setLogo(mConversationAvatar); |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 1016 | } |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 1017 | } |
| 1018 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1019 | public void blockContactRequest() { |
| 1020 | presenter.onBlockIncomingContactRequest(); |
| 1021 | } |
| 1022 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1023 | public void refuseContactRequest() { |
| 1024 | presenter.onRefuseIncomingContactRequest(); |
| 1025 | } |
| 1026 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1027 | public void acceptContactRequest() { |
| 1028 | presenter.onAcceptIncomingContactRequest(); |
| 1029 | } |
| 1030 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1031 | public void addContact() { |
| 1032 | presenter.onAddContact(); |
| 1033 | } |
| 1034 | |
| 1035 | @Override |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 1036 | public void onPrepareOptionsMenu(@NonNull Menu menu) { |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 1037 | super.onPrepareOptionsMenu(menu); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1038 | boolean visible = binding.cvMessageInput.getVisibility() == View.VISIBLE; |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 1039 | if (mAudioCallBtn != null) |
| 1040 | mAudioCallBtn.setVisible(visible); |
| 1041 | if (mVideoCallBtn != null) |
| 1042 | mVideoCallBtn.setVisible(visible); |
| 1043 | } |
| 1044 | |
| 1045 | @Override |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1046 | public void switchToUnknownView(String contactDisplayName) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1047 | binding.cvMessageInput.setVisibility(View.GONE); |
| 1048 | binding.unknownContactPrompt.setVisibility(View.VISIBLE); |
| 1049 | binding.trustRequestPrompt.setVisibility(View.GONE); |
| 1050 | binding.tvTrustRequestMessage.setText(String.format(getString(R.string.message_contact_not_trusted), contactDisplayName)); |
| 1051 | binding.trustRequestMessageLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 1052 | currentBottomView = binding.unknownContactPrompt; |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 1053 | requireActivity().invalidateOptionsMenu(); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 1054 | updateListPadding(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1057 | @Override |
| 1058 | public void switchToIncomingTrustRequestView(String contactDisplayName) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1059 | binding.cvMessageInput.setVisibility(View.GONE); |
| 1060 | binding.unknownContactPrompt.setVisibility(View.GONE); |
| 1061 | binding.trustRequestPrompt.setVisibility(View.VISIBLE); |
| 1062 | binding.tvTrustRequestMessage.setText(String.format(getString(R.string.message_contact_not_trusted_yet), contactDisplayName)); |
| 1063 | binding.trustRequestMessageLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 1064 | currentBottomView = binding.trustRequestPrompt; |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 1065 | requireActivity().invalidateOptionsMenu(); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 1066 | updateListPadding(); |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | @Override |
| 1070 | public void switchToConversationView() { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1071 | binding.cvMessageInput.setVisibility(View.VISIBLE); |
| 1072 | binding.unknownContactPrompt.setVisibility(View.GONE); |
| 1073 | binding.trustRequestPrompt.setVisibility(View.GONE); |
| 1074 | binding.trustRequestMessageLayout.setVisibility(View.GONE); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 1075 | currentBottomView = binding.cvMessageInput; |
Adrien Béraud | 4493948 | 2019-02-13 21:42:08 -0500 | [diff] [blame] | 1076 | requireActivity().invalidateOptionsMenu(); |
Adrien Béraud | 0dcc71b | 2019-09-25 13:23:44 -0400 | [diff] [blame] | 1077 | updateListPadding(); |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | @Override |
| 1081 | public void positiveMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 1082 | presenter.clickOnGoingPane(); |
| 1083 | } |
| 1084 | |
| 1085 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1086 | public void negativeMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 1087 | presenter.clickOnGoingPane(); |
| 1088 | } |
| 1089 | |
| 1090 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1091 | public void toggleMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 1092 | presenter.clickOnGoingPane(); |
| 1093 | } |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 1094 | |
| 1095 | private void setLoading(boolean isLoading) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1096 | if (binding == null) |
Adrien Béraud | 5b47cb5 | 2018-07-06 16:24:14 -0400 | [diff] [blame] | 1097 | return; |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 1098 | if (isLoading) { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1099 | binding.btnTakePicture.setVisibility(View.GONE); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1100 | binding.pbDataTransfer.setVisibility(View.VISIBLE); |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 1101 | } else { |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1102 | binding.btnTakePicture.setVisibility(View.VISIBLE); |
Adrien Béraud | b28c491 | 2018-12-02 22:58:52 -0500 | [diff] [blame] | 1103 | binding.pbDataTransfer.setVisibility(View.GONE); |
Pierre Duchemin | 17542a7 | 2018-02-14 16:38:36 -0500 | [diff] [blame] | 1104 | } |
| 1105 | } |
Adrien Béraud | 1b8ac9f | 2018-05-31 14:34:23 -0400 | [diff] [blame] | 1106 | |
Adrien Béraud | ae45ffa | 2018-07-06 16:21:29 -0400 | [diff] [blame] | 1107 | public void handleShareIntent(Intent intent) { |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 1108 | Log.w(TAG, "handleShareIntent " + intent); |
| 1109 | |
| 1110 | String action = intent.getAction(); |
| 1111 | if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) { |
| 1112 | String type = intent.getType(); |
| 1113 | if (type == null) { |
| 1114 | Log.w(TAG, "Can't share with no type"); |
Adrien Béraud | ae45ffa | 2018-07-06 16:21:29 -0400 | [diff] [blame] | 1115 | return; |
Adrien Béraud | 5477ce8 | 2020-02-24 11:13:54 -0500 | [diff] [blame] | 1116 | } |
| 1117 | if (type.startsWith("text/plain")) { |
| 1118 | binding.msgInputTxt.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); |
| 1119 | } else { |
| 1120 | android.net.Uri uri = intent.getData(); |
| 1121 | ClipData clip = intent.getClipData(); |
| 1122 | if (uri == null && clip != null && clip.getItemCount() > 0) |
| 1123 | uri = clip.getItemAt(0).getUri(); |
| 1124 | if (uri == null) |
| 1125 | return; |
| 1126 | startFileSend(AndroidFileUtils.getCacheFile(requireContext(), uri).flatMapCompletable(this::sendFile)); |
| 1127 | } |
| 1128 | } else if (Intent.ACTION_VIEW.equals(action)) { |
| 1129 | ConversationPath path = ConversationPath.fromIntent(intent); |
| 1130 | if (path != null && intent.getBooleanExtra(EXTRA_SHOW_MAP, false)) { |
| 1131 | shareLocation(); |
| 1132 | } |
Adrien Béraud | ae45ffa | 2018-07-06 16:21:29 -0400 | [diff] [blame] | 1133 | } |
| 1134 | } |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 1135 | |
| 1136 | /** |
| 1137 | * Creates an intent using Android Storage Access Framework |
| 1138 | * This intent is then received by applications that can handle it like |
| 1139 | * Downloads or Google drive |
| 1140 | * @param file DataTransfer of the file that is going to be stored |
| 1141 | * @param currentFileAbsolutePath absolute path of the file we want to save |
| 1142 | */ |
| 1143 | public void startSaveFile(DataTransfer file, String currentFileAbsolutePath){ |
| 1144 | //Get the current file absolute path and store it |
| 1145 | mCurrentFileAbsolutePath = currentFileAbsolutePath; |
| 1146 | |
| 1147 | //Use Android Storage File Access to download the file |
| 1148 | Intent downloadFileIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT); |
| 1149 | downloadFileIntent.setType(AndroidFileUtils.getMimeTypeFromExtension(file.getExtension())); |
amine younes | 7c56f31 | 2019-06-10 11:34:25 -0400 | [diff] [blame] | 1150 | downloadFileIntent.addCategory(Intent.CATEGORY_OPENABLE); |
| 1151 | downloadFileIntent.putExtra(Intent.EXTRA_TITLE,file.getDisplayName()); |
| 1152 | |
| 1153 | startActivityForResult(downloadFileIntent, ConversationFragment.REQUEST_CODE_SAVE_FILE); |
| 1154 | } |
| 1155 | |
Amirhossein | e0846c5 | 2020-03-12 15:34:35 -0400 | [diff] [blame] | 1156 | @Override |
| 1157 | public void displayNetworkErrorPanel() { |
Adrien Béraud | c35f7f4 | 2020-04-15 15:29:29 -0400 | [diff] [blame] | 1158 | if (binding != null) { |
| 1159 | binding.errorMsgPane.setVisibility(View.VISIBLE); |
Adrien Béraud | c279092 | 2020-04-28 17:34:03 -0400 | [diff] [blame] | 1160 | binding.errorMsgPane.setOnClickListener(null); |
| 1161 | binding.errorMsgPane.setText(R.string.error_no_network); |
Amirhossein | e0846c5 | 2020-03-12 15:34:35 -0400 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | @Override |
| 1166 | public void hideErrorPanel() { |
Adrien Béraud | c35f7f4 | 2020-04-15 15:29:29 -0400 | [diff] [blame] | 1167 | if (binding != null) { |
| 1168 | binding.errorMsgPane.setVisibility(View.GONE); |
Amirhossein | e0846c5 | 2020-03-12 15:34:35 -0400 | [diff] [blame] | 1169 | } |
Amirhossein | e0846c5 | 2020-03-12 15:34:35 -0400 | [diff] [blame] | 1170 | } |
| 1171 | |
Adrien Béraud | e32ab74 | 2018-08-25 21:15:08 -0400 | [diff] [blame] | 1172 | } |