Commit a1aee92d authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin
Browse files

sharewith: route trough home

Change-Id: Ie253fab6909fc7de95ad894c7e602eb140fb8ebb
parent 64f70d4d
...@@ -143,7 +143,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -143,7 +143,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
private ActivityHomeBinding mBinding; private ActivityHomeBinding mBinding;
private AlertDialog mMigrationDialog; private AlertDialog mMigrationDialog;
private String mAccountWithPendingrequests = null; //private String mAccountWithPendingrequests = null;
private final CompositeDisposable mDisposable = new CompositeDisposable(); private final CompositeDisposable mDisposable = new CompositeDisposable();
...@@ -197,30 +197,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -197,30 +197,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
}); });
} }
// if app opened from notification display trust request fragment when mService will connected
/*Intent intent = getIntent();
Bundle extra = intent.getExtras();
String action = intent.getAction();
if (ACTION_PRESENT_TRUST_REQUEST_FRAGMENT.equals(action)) {
if (extra == null || extra.getString(ContactRequestsFragment.ACCOUNT_ID) == null) {
return;
}
mAccountWithPendingrequests = extra.getString(ContactRequestsFragment.ACCOUNT_ID);
} else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
handleShareIntent(intent);
}
FragmentManager fragmentManager = getSupportFragmentManager();
fContent = fragmentManager.findFragmentById(R.id.main_frame);
if (fContent == null || Intent.ACTION_SEARCH.equals(action)) {
fContent = new SmartListFragment();
fragmentManager.beginTransaction()
.replace(R.id.main_frame, fContent, HOME_TAG)
.commitNow();
}
if (mAccountWithPendingrequests != null) {
presentTrustRequestFragment(mAccountWithPendingrequests);
mAccountWithPendingrequests = null;
}*/
handleIntent(getIntent()); handleIntent(getIntent());
} }
...@@ -237,39 +213,10 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -237,39 +213,10 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
mBinding = null; mBinding = null;
} }
private void handleShareIntent(Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
Bundle extra = intent.getExtras();
if (extra != null) {
if (ConversationPath.fromBundle(extra) != null) {
intent.setClass(this, ConversationActivity.class);
startActivity(intent);
}
}
}
}
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
/*Log.d(TAG, "onNewIntent: " + intent); handleIntent(intent);
String action = intent.getAction();
if (ACTION_PRESENT_TRUST_REQUEST_FRAGMENT.equals(action)) {
Bundle extra = intent.getExtras();
if (extra == null || extra.getString(ContactRequestsFragment.ACCOUNT_ID) == null) {
return;
}
presentTrustRequestFragment(extra.getString(ContactRequestsFragment.ACCOUNT_ID));
} else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
handleShareIntent(intent);
} else if (Intent.ACTION_SEARCH.equals(action)) {
if (fContent instanceof SmartListFragment) {
((SmartListFragment)fContent).handleIntent(intent);
}
} else if (DRingService.ACTION_CONV_ACCEPT.equals(action) || Intent.ACTION_VIEW.equals(action)) {
startConversation(ConversationPath.fromIntent(intent));
}*/
} }
private void handleIntent(Intent intent) { private void handleIntent(Intent intent) {
...@@ -285,15 +232,13 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -285,15 +232,13 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
} else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) { } else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
ConversationPath path = ConversationPath.fromBundle(extra); ConversationPath path = ConversationPath.fromBundle(extra);
if (path != null) { if (path != null) {
startConversation(path);
intent.setClass(this, ConversationActivity.class); } else {
intent.setClass(getApplicationContext(), ShareActivity.class);
startActivity(intent); startActivity(intent);
} }
} else if (DRingService.ACTION_CONV_ACCEPT.equals(action) || Intent.ACTION_VIEW.equals(action)) { } else if (DRingService.ACTION_CONV_ACCEPT.equals(action) || Intent.ACTION_VIEW.equals(action)) {
startConversation(ConversationPath.fromIntent(intent)); startConversation(ConversationPath.fromIntent(intent));
/*if (DeviceUtils.isTablet(this)) {
startConversationTablet(ConversationPath.fromIntent(intent).toBundle());
}*/
} //else { } //else {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
fContent = fragmentManager.findFragmentById(R.id.main_frame); fContent = fragmentManager.findFragmentById(R.id.main_frame);
...@@ -395,16 +340,14 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -395,16 +340,14 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mDisposable.add((mAccountService mDisposable.add((mAccountService
.getCurrentAccountSubject() .getCurrentAccountSubject()
.flatMap(Account::getConversationsSubject)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.map(account -> {
Collection<Conversation> conversations = account.getConversations();
synchronized (conversations) {
return new ArrayList<>(conversations);
}
})
.subscribe(this::setShareShortcuts, e -> Log.e(TAG, "Error generating conversation shortcuts", e)))); .subscribe(this::setShareShortcuts, e -> Log.e(TAG, "Error generating conversation shortcuts", e))));
} }
if (fConversation == null)
fConversation = (ConversationFragment) getSupportFragmentManager().findFragmentByTag(ConversationFragment.class.getSimpleName());
int newOrientation = getResources().getConfiguration().orientation; int newOrientation = getResources().getConfiguration().orientation;
if (mOrientation != newOrientation) { if (mOrientation != newOrientation) {
mOrientation = newOrientation; mOrientation = newOrientation;
...@@ -414,12 +357,11 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -414,12 +357,11 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
showTabletToolbar(); showTabletToolbar();
} else { } else {
// Remove ConversationFragment that might have been restored after an orientation change // Remove ConversationFragment that might have been restored after an orientation change
if (fConversation == null)
fConversation = (ConversationFragment) getSupportFragmentManager().findFragmentByTag(ConversationFragment.class.getSimpleName());
if (fConversation != null) { if (fConversation != null) {
// fConversation = null; getSupportFragmentManager()
// getSupportFragmentManager().findFragmentByTag(ConversationFragment.class.getSimpleName()); .beginTransaction()
getSupportFragmentManager().beginTransaction().remove(fConversation).commitNow(); .remove(fConversation)
.commitNow();
fConversation = null; fConversation = null;
} }
} }
...@@ -834,8 +776,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -834,8 +776,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
List<Future<Bitmap>> futureIcons = new ArrayList<>(Math.min(conversations.size(),maxCount)); List<Future<Bitmap>> futureIcons = new ArrayList<>(Math.min(conversations.size(),maxCount));
for (Conversation conversation : conversations) { for (Conversation conversation : conversations) {
Contact contact = conversation.getContact(); futureIcons.add(AvatarFactory.getBitmapAvatar(this, conversation, targetSize, false)
futureIcons.add(AvatarFactory.getBitmapAvatar(this, contact, targetSize)
.subscribeOn(Schedulers.computation()) .subscribeOn(Schedulers.computation())
.toFuture()); .toFuture());
if (++i == maxCount) if (++i == maxCount)
...@@ -845,7 +786,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -845,7 +786,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
i = 0; i = 0;
for (Conversation conversation : conversations) { for (Conversation conversation : conversations) {
Contact contact = conversation.getContact();
IconCompat icon = null; IconCompat icon = null;
try { try {
icon = IconCompat.createWithBitmap(futureIcons.get(i).get()); icon = IconCompat.createWithBitmap(futureIcons.get(i).get());
...@@ -853,21 +793,22 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV ...@@ -853,21 +793,22 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
Log.w(TAG, "Failed to load icon", e); Log.w(TAG, "Failed to load icon", e);
} }
Bundle bundle = ConversationPath.toBundle(conversation.getAccountId(), contact.getPrimaryNumber()); ConversationPath path = new ConversationPath(conversation);
String key = ConversationPath.toKey(conversation.getAccountId(), contact.getPrimaryNumber()); String key = path.toKey();
Person person = new Person.Builder() Person person = new Person.Builder()
.setName(contact.getDisplayName()) .setName(conversation.getTitle())
.setKey(key) .setKey(key)
.build(); .build();
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, key) ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, key)
.setShortLabel(contact.getDisplayName()) .setShortLabel(conversation.getTitle())
.setPerson(person) .setPerson(person)
.setLongLived(true) .setLongLived(true)
.setIcon(icon) .setIcon(icon)
.setCategories(Collections.singleton(CONVERSATIONS_CATEGORY)) .setCategories(Collections.singleton(CONVERSATIONS_CATEGORY))
.setIntent(new Intent(Intent.ACTION_SEND, Uri.EMPTY, this, ShareActivity.class).putExtras(bundle)) .setIntent(new Intent(Intent.ACTION_SEND, Uri.EMPTY, this, HomeActivity.class)
.putExtras(path.toBundle()))
.build(); .build();
shortcutInfoList.add(shortcutInfo); shortcutInfoList.add(shortcutInfo);
......
/*
* Copyright (C) 2004-2021 Savoir-faire Linux Inc.
*
* Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cx.ring.client; package cx.ring.client;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import cx.ring.R; import cx.ring.R;
import cx.ring.utils.ConversationPath;
public class ShareActivity extends AppCompatActivity { public class ShareActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle extra = intent.getExtras();
if (ConversationPath.fromBundle(extra) != null) {
intent.setClass(this, ConversationActivity.class);
startActivity(intent);
finish();
return;
}
setContentView(R.layout.activity_share); setContentView(R.layout.activity_share);
} }
......
...@@ -24,33 +24,30 @@ import android.content.Context; ...@@ -24,33 +24,30 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.util.Log; import net.jami.facades.ConversationFacade;
import android.view.InflateException; import net.jami.services.ContactService;
import android.view.LayoutInflater; import net.jami.smartlist.SmartListViewModel;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import cx.ring.R;
import cx.ring.adapters.SmartListAdapter; import cx.ring.adapters.SmartListAdapter;
import cx.ring.application.JamiApplication; import cx.ring.application.JamiApplication;
import cx.ring.client.ConversationActivity; import cx.ring.client.ConversationActivity;
import net.jami.facades.ConversationFacade; import cx.ring.databinding.FragSharewithBinding;
import net.jami.services.ContactService;
import net.jami.smartlist.SmartListViewModel;
import cx.ring.utils.ConversationPath; import cx.ring.utils.ConversationPath;
import cx.ring.viewholders.SmartListViewHolder; import cx.ring.viewholders.SmartListViewHolder;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
...@@ -58,7 +55,6 @@ import io.reactivex.disposables.CompositeDisposable; ...@@ -58,7 +55,6 @@ import io.reactivex.disposables.CompositeDisposable;
public class ShareWithFragment extends Fragment { public class ShareWithFragment extends Fragment {
private final static String TAG = ShareWithFragment.class.getSimpleName(); private final static String TAG = ShareWithFragment.class.getSimpleName();
private final static String SHORTCUT_ID = "android.intent.extra.shortcut.ID";
private final CompositeDisposable mDisposable = new CompositeDisposable(); private final CompositeDisposable mDisposable = new CompositeDisposable();
...@@ -73,9 +69,7 @@ public class ShareWithFragment extends Fragment { ...@@ -73,9 +69,7 @@ public class ShareWithFragment extends Fragment {
private Intent mPendingIntent = null; private Intent mPendingIntent = null;
private SmartListAdapter adapter; private SmartListAdapter adapter;
private TextView previewText; private FragSharewithBinding binding;
private ImageView previewImage;
private VideoView previewVideo;
/** /**
* Mandatory empty constructor for the fragment manager to instantiate the * Mandatory empty constructor for the fragment manager to instantiate the
...@@ -90,20 +84,15 @@ public class ShareWithFragment extends Fragment { ...@@ -90,20 +84,15 @@ public class ShareWithFragment extends Fragment {
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag_sharewith, container, false); binding = FragSharewithBinding.inflate(inflater);
RecyclerView list = view.findViewById(R.id.shareList);
Toolbar toolbar = view.findViewById(R.id.toolbar); Context context = binding.getRoot().getContext();
previewText = view.findViewById(R.id.previewText);
previewImage = view.findViewById(R.id.previewImage);
previewVideo = view.findViewById(R.id.previewVideo);
Context context = view.getContext();
Activity activity = getActivity(); Activity activity = getActivity();
if (activity instanceof AppCompatActivity) { if (activity instanceof AppCompatActivity) {
AppCompatActivity compatActivity = (AppCompatActivity) activity; AppCompatActivity compatActivity = (AppCompatActivity) activity;
compatActivity.setSupportActionBar(toolbar); compatActivity.setSupportActionBar(binding.toolbar);
ActionBar ab = compatActivity.getSupportActionBar(); ActionBar ab = compatActivity.getSupportActionBar();
if (ab != null) if (ab != null)
ab.setDisplayHomeAsUpEnabled(true); ab.setDisplayHomeAsUpEnabled(true);
...@@ -113,25 +102,25 @@ public class ShareWithFragment extends Fragment { ...@@ -113,25 +102,25 @@ public class ShareWithFragment extends Fragment {
String type = mPendingIntent.getType(); String type = mPendingIntent.getType();
ClipData clip = mPendingIntent.getClipData(); ClipData clip = mPendingIntent.getClipData();
if (type.startsWith("text/")) { if (type.startsWith("text/")) {
previewText.setText(mPendingIntent.getStringExtra(Intent.EXTRA_TEXT)); binding.previewText.setText(mPendingIntent.getStringExtra(Intent.EXTRA_TEXT));
previewText.setVisibility(View.VISIBLE); binding.previewText.setVisibility(View.VISIBLE);
} else if (type.startsWith("image/")) { } else if (type.startsWith("image/")) {
Uri data = mPendingIntent.getData(); Uri data = mPendingIntent.getData();
if (data == null && clip != null && clip.getItemCount() > 0) if (data == null && clip != null && clip.getItemCount() > 0)
data = clip.getItemAt(0).getUri(); data = clip.getItemAt(0).getUri();
previewImage.setImageURI(data); binding.previewImage.setImageURI(data);
previewImage.setVisibility(View.VISIBLE); binding.previewImage.setVisibility(View.VISIBLE);
} else if (type.startsWith("video/")) { } else if (type.startsWith("video/")) {
Uri data = mPendingIntent.getData(); Uri data = mPendingIntent.getData();
if (data == null && clip != null && clip.getItemCount() > 0) if (data == null && clip != null && clip.getItemCount() > 0)
data = clip.getItemAt(0).getUri(); data = clip.getItemAt(0).getUri();
try { try {
previewVideo.setVideoURI(data); binding.previewVideo.setVideoURI(data);
previewVideo.setVisibility(View.VISIBLE); binding.previewVideo.setVisibility(View.VISIBLE);
} catch (NullPointerException | InflateException | NumberFormatException e) { } catch (NullPointerException | InflateException | NumberFormatException e) {
Log.e(TAG, e.getMessage()); Log.e(TAG, e.getMessage());
} }
previewVideo.setOnCompletionListener(mediaPlayer -> previewVideo.start()); binding.previewVideo.setOnCompletionListener(mediaPlayer -> binding.previewVideo.start());
} }
} }
...@@ -143,7 +132,7 @@ public class ShareWithFragment extends Fragment { ...@@ -143,7 +132,7 @@ public class ShareWithFragment extends Fragment {
mPendingIntent = null; mPendingIntent = null;
String type = intent.getType(); String type = intent.getType();
if (type != null && type.startsWith("text/")) { if (type != null && type.startsWith("text/")) {
intent.putExtra(Intent.EXTRA_TEXT, previewText.getText().toString()); intent.putExtra(Intent.EXTRA_TEXT, binding.previewText.getText().toString());
} }
intent.putExtras(ConversationPath.toBundle(smartListViewModel.getAccountId(), smartListViewModel.getUri())); intent.putExtras(ConversationPath.toBundle(smartListViewModel.getAccountId(), smartListViewModel.getUri()));
intent.setClass(requireActivity(), ConversationActivity.class); intent.setClass(requireActivity(), ConversationActivity.class);
...@@ -156,9 +145,9 @@ public class ShareWithFragment extends Fragment { ...@@ -156,9 +145,9 @@ public class ShareWithFragment extends Fragment {
} }
}, mDisposable); }, mDisposable);
list.setLayoutManager(new LinearLayoutManager(context)); binding.shareList.setLayoutManager(new LinearLayoutManager(context));
list.setAdapter(adapter); binding.shareList.setAdapter(adapter);
return view; return binding.getRoot();
} }
@Override @Override
...@@ -174,8 +163,8 @@ public class ShareWithFragment extends Fragment { ...@@ -174,8 +163,8 @@ public class ShareWithFragment extends Fragment {
if (adapter != null) if (adapter != null)
adapter.update(list); adapter.update(list);
})); }));
if (previewVideo != null && previewVideo.getVisibility() != View.GONE) { if (binding != null && binding.previewVideo.getVisibility() != View.GONE) {
previewVideo.start(); binding.previewVideo.start();
} }
} }
...@@ -186,24 +175,16 @@ public class ShareWithFragment extends Fragment { ...@@ -186,24 +175,16 @@ public class ShareWithFragment extends Fragment {
} }
@Override @Override
public void onCreate(Bundle bundle) { public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle); super.onCreate(bundle);
Intent intent = getActivity().getIntent(); /*Intent intent = getActivity().getIntent();
Bundle extra = intent.getExtras(); Bundle extra = intent.getExtras();
if (extra != null) { if (ConversationPath.fromBundle(extra) != null) {
if (ConversationPath.fromBundle(extra) != null) { intent.setClass(getActivity(), ConversationActivity.class);
intent.setClass(getActivity(), ConversationActivity.class); startActivity(intent);
startActivity(intent); return;
return; }*/
} else if (intent.hasExtra(SHORTCUT_ID)) { mPendingIntent = getActivity().getIntent();
ConversationPath conversationPath = ConversationPath.fromKey(extra.getString(SHORTCUT_ID));
intent.setClass(getActivity(), ConversationActivity.class)
.putExtras(conversationPath.toBundle());
startActivity(intent);
return;
}
}
mPendingIntent = intent;
} }
@Override @Override
......
...@@ -25,6 +25,7 @@ import android.text.TextUtils; ...@@ -25,6 +25,7 @@ import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.pm.ShortcutManagerCompat;
import net.jami.model.Conversation; import net.jami.model.Conversation;
import net.jami.model.Interaction; import net.jami.model.Interaction;
...@@ -161,6 +162,10 @@ public class ConversationPath { ...@@ -161,6 +162,10 @@ public class ConversationPath {
String contactId = bundle.getString(KEY_CONVERSATION_URI); String contactId = bundle.getString(KEY_CONVERSATION_URI);
if (accountId != null && contactId != null) { if (accountId != null && contactId != null) {
return new ConversationPath(accountId, contactId); return new ConversationPath(accountId, contactId);
} else {
String shortcutId = bundle.getString(ShortcutManagerCompat.EXTRA_SHORTCUT_ID);
if (shortcutId != null)
return fromKey(shortcutId);
} }
} }
return null; return null;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or