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