Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
private ActivityHomeBinding mBinding;
private AlertDialog mMigrationDialog;
private String mAccountWithPendingrequests = null;
//private String mAccountWithPendingrequests = null;
private final CompositeDisposable mDisposable = new CompositeDisposable();
......@@ -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());
}
......@@ -237,39 +213,10 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
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
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
/*Log.d(TAG, "onNewIntent: " + 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));
}*/
handleIntent(intent);
}
private void handleIntent(Intent intent) {
......@@ -285,15 +232,13 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
} else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
ConversationPath path = ConversationPath.fromBundle(extra);
if (path != null) {
intent.setClass(this, ConversationActivity.class);
startConversation(path);
} else {
intent.setClass(getApplicationContext(), ShareActivity.class);
startActivity(intent);
}
} else if (DRingService.ACTION_CONV_ACCEPT.equals(action) || Intent.ACTION_VIEW.equals(action)) {
startConversation(ConversationPath.fromIntent(intent));
/*if (DeviceUtils.isTablet(this)) {
startConversationTablet(ConversationPath.fromIntent(intent).toBundle());
}*/
} //else {
FragmentManager fragmentManager = getSupportFragmentManager();
fContent = fragmentManager.findFragmentById(R.id.main_frame);
......@@ -395,16 +340,14 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mDisposable.add((mAccountService
.getCurrentAccountSubject()
.flatMap(Account::getConversationsSubject)
.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))));
}
if (fConversation == null)
fConversation = (ConversationFragment) getSupportFragmentManager().findFragmentByTag(ConversationFragment.class.getSimpleName());
int newOrientation = getResources().getConfiguration().orientation;
if (mOrientation != newOrientation) {
mOrientation = newOrientation;
......@@ -414,12 +357,11 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
showTabletToolbar();
} else {
// Remove ConversationFragment that might have been restored after an orientation change
if (fConversation == null)
fConversation = (ConversationFragment) getSupportFragmentManager().findFragmentByTag(ConversationFragment.class.getSimpleName());
if (fConversation != null) {
// fConversation = null;
// getSupportFragmentManager().findFragmentByTag(ConversationFragment.class.getSimpleName());
getSupportFragmentManager().beginTransaction().remove(fConversation).commitNow();
getSupportFragmentManager()
.beginTransaction()
.remove(fConversation)
.commitNow();
fConversation = null;
}
}
......@@ -834,8 +776,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
List<Future<Bitmap>> futureIcons = new ArrayList<>(Math.min(conversations.size(),maxCount));
for (Conversation conversation : conversations) {
Contact contact = conversation.getContact();
futureIcons.add(AvatarFactory.getBitmapAvatar(this, contact, targetSize)
futureIcons.add(AvatarFactory.getBitmapAvatar(this, conversation, targetSize, false)
.subscribeOn(Schedulers.computation())
.toFuture());
if (++i == maxCount)
......@@ -845,7 +786,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
i = 0;
for (Conversation conversation : conversations) {
Contact contact = conversation.getContact();
IconCompat icon = null;
try {
icon = IconCompat.createWithBitmap(futureIcons.get(i).get());
......@@ -853,21 +793,22 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
Log.w(TAG, "Failed to load icon", e);
}
Bundle bundle = ConversationPath.toBundle(conversation.getAccountId(), contact.getPrimaryNumber());
String key = ConversationPath.toKey(conversation.getAccountId(), contact.getPrimaryNumber());
ConversationPath path = new ConversationPath(conversation);
String key = path.toKey();
Person person = new Person.Builder()
.setName(contact.getDisplayName())
.setName(conversation.getTitle())
.setKey(key)
.build();
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, key)
.setShortLabel(contact.getDisplayName())
.setShortLabel(conversation.getTitle())
.setPerson(person)
.setLongLived(true)
.setIcon(icon)
.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();
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;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import cx.ring.R;
import cx.ring.utils.ConversationPath;
public class ShareActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle 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);
}
......
......@@ -24,33 +24,30 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
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.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;
import net.jami.facades.ConversationFacade;
import net.jami.services.ContactService;
import net.jami.smartlist.SmartListViewModel;
import javax.inject.Inject;
import javax.inject.Singleton;
import cx.ring.R;
import cx.ring.adapters.SmartListAdapter;
import cx.ring.application.JamiApplication;
import cx.ring.client.ConversationActivity;
import net.jami.facades.ConversationFacade;
import net.jami.services.ContactService;
import net.jami.smartlist.SmartListViewModel;
import cx.ring.databinding.FragSharewithBinding;
import cx.ring.utils.ConversationPath;
import cx.ring.viewholders.SmartListViewHolder;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -58,7 +55,6 @@ import io.reactivex.disposables.CompositeDisposable;
public class ShareWithFragment extends Fragment {
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();
......@@ -73,9 +69,7 @@ public class ShareWithFragment extends Fragment {
private Intent mPendingIntent = null;
private SmartListAdapter adapter;
private TextView previewText;
private ImageView previewImage;
private VideoView previewVideo;
private FragSharewithBinding binding;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
......@@ -90,20 +84,15 @@ public class ShareWithFragment extends Fragment {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag_sharewith, container, false);
RecyclerView list = view.findViewById(R.id.shareList);
Toolbar toolbar = view.findViewById(R.id.toolbar);
previewText = view.findViewById(R.id.previewText);
previewImage = view.findViewById(R.id.previewImage);
previewVideo = view.findViewById(R.id.previewVideo);
Context context = view.getContext();
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
binding = FragSharewithBinding.inflate(inflater);
Context context = binding.getRoot().getContext();
Activity activity = getActivity();
if (activity instanceof AppCompatActivity) {
AppCompatActivity compatActivity = (AppCompatActivity) activity;
compatActivity.setSupportActionBar(toolbar);
compatActivity.setSupportActionBar(binding.toolbar);
ActionBar ab = compatActivity.getSupportActionBar();
if (ab != null)
ab.setDisplayHomeAsUpEnabled(true);
......@@ -113,25 +102,25 @@ public class ShareWithFragment extends Fragment {
String type = mPendingIntent.getType();
ClipData clip = mPendingIntent.getClipData();
if (type.startsWith("text/")) {
previewText.setText(mPendingIntent.getStringExtra(Intent.EXTRA_TEXT));
previewText.setVisibility(View.VISIBLE);
binding.previewText.setText(mPendingIntent.getStringExtra(Intent.EXTRA_TEXT));
binding.previewText.setVisibility(View.VISIBLE);
} else if (type.startsWith("image/")) {
Uri data = mPendingIntent.getData();
if (data == null && clip != null && clip.getItemCount() > 0)
data = clip.getItemAt(0).getUri();
previewImage.setImageURI(data);
previewImage.setVisibility(View.VISIBLE);
binding.previewImage.setImageURI(data);
binding.previewImage.setVisibility(View.VISIBLE);
} else if (type.startsWith("video/")) {
Uri data = mPendingIntent.getData();
if (data == null && clip != null && clip.getItemCount() > 0)
data = clip.getItemAt(0).getUri();
try {
previewVideo.setVideoURI(data);
previewVideo.setVisibility(View.VISIBLE);
binding.previewVideo.setVideoURI(data);
binding.previewVideo.setVisibility(View.VISIBLE);
} catch (NullPointerException | InflateException | NumberFormatException e) {
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 {
mPendingIntent = null;
String type = intent.getType();
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.setClass(requireActivity(), ConversationActivity.class);
......@@ -156,9 +145,9 @@ public class ShareWithFragment extends Fragment {
}
}, mDisposable);
list.setLayoutManager(new LinearLayoutManager(context));
list.setAdapter(adapter);
return view;
binding.shareList.setLayoutManager(new LinearLayoutManager(context));
binding.shareList.setAdapter(adapter);
return binding.getRoot();
}
@Override
......@@ -174,8 +163,8 @@ public class ShareWithFragment extends Fragment {
if (adapter != null)
adapter.update(list);
}));
if (previewVideo != null && previewVideo.getVisibility() != View.GONE) {
previewVideo.start();
if (binding != null && binding.previewVideo.getVisibility() != View.GONE) {
binding.previewVideo.start();
}
}
......@@ -186,24 +175,16 @@ public class ShareWithFragment extends Fragment {
}
@Override
public void onCreate(Bundle bundle) {
public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle);
Intent intent = getActivity().getIntent();
/*Intent intent = getActivity().getIntent();
Bundle extra = intent.getExtras();
if (extra != null) {
if (ConversationPath.fromBundle(extra) != null) {
intent.setClass(getActivity(), ConversationActivity.class);
startActivity(intent);
return;
} else if (intent.hasExtra(SHORTCUT_ID)) {
ConversationPath conversationPath = ConversationPath.fromKey(extra.getString(SHORTCUT_ID));
intent.setClass(getActivity(), ConversationActivity.class)
.putExtras(conversationPath.toBundle());
startActivity(intent);
return;
}
}
mPendingIntent = intent;
}*/
mPendingIntent = getActivity().getIntent();
}
@Override
......
......@@ -25,6 +25,7 @@ import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.pm.ShortcutManagerCompat;
import net.jami.model.Conversation;
import net.jami.model.Interaction;
......@@ -161,6 +162,10 @@ public class ConversationPath {
String contactId = bundle.getString(KEY_CONVERSATION_URI);
if (accountId != null && contactId != null) {
return new ConversationPath(accountId, contactId);
} else {
String shortcutId = bundle.getString(ShortcutManagerCompat.EXTRA_SHORTCUT_ID);
if (shortcutId != null)
return fromKey(shortcutId);
}
}
return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment