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