mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-03 05:03:04 +00:00
tidy up
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
bec19428e0
commit
9423376ca7
@ -62,7 +62,7 @@ import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.kennyc.bottomsheet.BottomSheet;
|
||||
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.activities.MainActivity;
|
||||
import com.nextcloud.talk.adapters.items.ConversationItem;
|
||||
@ -71,8 +71,6 @@ import com.nextcloud.talk.api.NcApi;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.controllers.bottomsheet.EntryMenuController;
|
||||
import com.nextcloud.talk.controllers.bottomsheet.OperationsMenuController;
|
||||
import com.nextcloud.talk.events.BottomSheetLockEvent;
|
||||
import com.nextcloud.talk.events.EventStatus;
|
||||
import com.nextcloud.talk.interfaces.ConversationMenuInterface;
|
||||
import com.nextcloud.talk.jobs.AccountRemovalWorker;
|
||||
@ -185,7 +183,6 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
private List<AbstractFlexibleItem> conversationItemsWithHeader = new ArrayList<>();
|
||||
private final List<AbstractFlexibleItem> searchableConversationItems = new ArrayList<>();
|
||||
|
||||
private BottomSheet bottomSheet;
|
||||
private MenuItem searchItem;
|
||||
private SearchView searchView;
|
||||
private String searchQuery;
|
||||
@ -311,7 +308,7 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
if (getActivity() != null && getActivity() instanceof MainActivity) {
|
||||
loadUserAvatar(((MainActivity) getActivity()).binding.switchAccountButton);
|
||||
}
|
||||
fetchData(false);
|
||||
fetchData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,7 +467,7 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
public void fetchData(boolean fromBottomSheet) {
|
||||
public void fetchData() {
|
||||
dispose(null);
|
||||
|
||||
isRefreshing = true;
|
||||
@ -670,7 +667,7 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
return false;
|
||||
});
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(() -> fetchData(false));
|
||||
swipeRefreshLayout.setOnRefreshListener(() -> fetchData());
|
||||
swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
|
||||
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.refresh_spinner_background);
|
||||
|
||||
@ -803,60 +800,23 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
return onQueryTextChange(query);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageEvent(BottomSheetLockEvent bottomSheetLockEvent) {
|
||||
if (bottomSheet != null) {
|
||||
if (!bottomSheetLockEvent.isCancelable()) {
|
||||
bottomSheet.setCancelable(bottomSheetLockEvent.isCancelable());
|
||||
} else {
|
||||
if (bottomSheetLockEvent.getDelay() != 0 && bottomSheetLockEvent.isShouldRefreshData()) {
|
||||
fetchData(true);
|
||||
} else {
|
||||
bottomSheet.setCancelable(bottomSheetLockEvent.isCancelable());
|
||||
if (bottomSheet.isShowing() && bottomSheetLockEvent.isCancel()) {
|
||||
bottomSheet.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void onMessageEvent(MoreMenuClickEvent moreMenuClickEvent) {
|
||||
//// Bundle bundle = new Bundle();
|
||||
//// Conversation conversation = moreMenuClickEvent.getConversation();
|
||||
//// bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation));
|
||||
//// bundle.putParcelable(BundleKeys.INSTANCE.getKEY_MENU_TYPE(), Parcels.wrap(CallMenuController.MenuType.REGULAR));
|
||||
////
|
||||
//// prepareAndShowBottomSheetWithBundle(bundle, true);
|
||||
// }
|
||||
|
||||
private void prepareAndShowBottomSheetWithBundle(Bundle bundle, boolean shouldShowCallMenuController) {
|
||||
private void prepareAndShowBottomSheetWithBundle(Bundle bundle) {
|
||||
if (view == null) {
|
||||
view = getActivity().getLayoutInflater().inflate(R.layout.bottom_sheet, null, false);
|
||||
}
|
||||
|
||||
if (shouldShowCallMenuController) {
|
||||
// if (shouldShowCallMenuController) {
|
||||
// getChildRouter((ViewGroup) view).setRoot(
|
||||
// RouterTransaction.with(new CallMenuController(bundle, this))
|
||||
// .popChangeHandler(new VerticalChangeHandler())
|
||||
// .pushChangeHandler(new VerticalChangeHandler()));
|
||||
|
||||
|
||||
} else {
|
||||
// } else {
|
||||
getChildRouter((ViewGroup) view).setRoot(
|
||||
RouterTransaction.with(new EntryMenuController(bundle))
|
||||
.popChangeHandler(new VerticalChangeHandler())
|
||||
.pushChangeHandler(new VerticalChangeHandler()));
|
||||
}
|
||||
|
||||
// if (bottomSheet == null) {
|
||||
// bottomSheet = new BottomSheet.Builder(getActivity()).setView(view).create();
|
||||
// }
|
||||
//
|
||||
//// bottomSheet.setOnShowListener(dialog -> new KeyboardUtils(getActivity(), bottomSheet.getLayout(), true));
|
||||
// bottomSheet.setOnDismissListener(dialog -> showSearchOrToolbar());
|
||||
// bottomSheet.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1057,11 +1017,15 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
bundle.putString(BundleKeys.INSTANCE.getKEY_ROOM_ID(), selectedConversation.getRoomId());
|
||||
bundle.putString(BundleKeys.INSTANCE.getKEY_SHARED_TEXT(), textToPaste);
|
||||
|
||||
if (selectedConversation.hasPassword && selectedConversation.participantType ==
|
||||
Participant.ParticipantType.GUEST ||
|
||||
selectedConversation.participantType == Participant.ParticipantType.USER_FOLLOWING_LINK) {
|
||||
// TODO debug & fix dialog???
|
||||
// when is hasPassword && ParticipantType.GUEST true? currently the app can't be used as guest?!
|
||||
// when is USER_FOLLOWING_LINK true? --> from contactsController via enter link?
|
||||
if ((selectedConversation.hasPassword
|
||||
&& selectedConversation.participantType == Participant.ParticipantType.GUEST)
|
||||
|| selectedConversation.participantType == Participant.ParticipantType.USER_FOLLOWING_LINK) {
|
||||
bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), 99);
|
||||
prepareAndShowBottomSheetWithBundle(bundle, false);
|
||||
prepareAndShowBottomSheetWithBundle(bundle);
|
||||
|
||||
} else {
|
||||
currentUser = userUtils.getCurrentUser();
|
||||
|
||||
@ -1077,7 +1041,7 @@ public class ConversationsListController extends BaseController implements Searc
|
||||
switch (eventStatus.getEventType()) {
|
||||
case CONVERSATION_UPDATE:
|
||||
if (eventStatus.isAllGood() && !isRefreshing) {
|
||||
fetchData(false);
|
||||
fetchData();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -1,363 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic <mario@lovelyhq.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 com.nextcloud.talk.controllers.bottomsheet;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.bluelinelabs.conductor.RouterTransaction;
|
||||
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
|
||||
import com.kennyc.bottomsheet.adapters.AppAdapter;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.adapters.items.AppItem;
|
||||
import com.nextcloud.talk.adapters.items.MenuItem;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.controllers.ConversationsListController;
|
||||
import com.nextcloud.talk.controllers.base.BaseController;
|
||||
import com.nextcloud.talk.events.BottomSheetLockEvent;
|
||||
import com.nextcloud.talk.interfaces.ConversationMenuInterface;
|
||||
import com.nextcloud.talk.jobs.LeaveConversationWorker;
|
||||
import com.nextcloud.talk.models.database.CapabilitiesUtil;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.ShareUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.parceler.Parcel;
|
||||
import org.parceler.Parcels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.work.Data;
|
||||
import androidx.work.OneTimeWorkRequest;
|
||||
import androidx.work.WorkManager;
|
||||
import autodagger.AutoInjector;
|
||||
import butterknife.BindView;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class CallMenuController extends BaseController implements FlexibleAdapter.OnItemClickListener {
|
||||
public static final int ALL_MESSAGES_READ = 0;
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
UserUtils userUtils;
|
||||
|
||||
@Inject
|
||||
Context context;
|
||||
|
||||
private Conversation conversation;
|
||||
private List<AbstractFlexibleItem> menuItems;
|
||||
private FlexibleAdapter<AbstractFlexibleItem> adapter;
|
||||
private MenuType menuType;
|
||||
private Intent shareIntent;
|
||||
|
||||
private UserEntity currentUser;
|
||||
private ConversationMenuInterface conversationMenuInterface;
|
||||
|
||||
public CallMenuController(Bundle args) {
|
||||
super(args);
|
||||
this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_ROOM()));
|
||||
if (args.containsKey(BundleKeys.INSTANCE.getKEY_MENU_TYPE())) {
|
||||
this.menuType = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_MENU_TYPE()));
|
||||
}
|
||||
}
|
||||
|
||||
public CallMenuController(Bundle args, @Nullable ConversationMenuInterface conversationMenuInterface) {
|
||||
super(args);
|
||||
this.conversation = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_ROOM()));
|
||||
if (args.containsKey(BundleKeys.INSTANCE.getKEY_MENU_TYPE())) {
|
||||
this.menuType = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_MENU_TYPE()));
|
||||
}
|
||||
this.conversationMenuInterface = conversationMenuInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
|
||||
return inflater.inflate(R.layout.controller_call_menu, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onViewBound(@NonNull View view) {
|
||||
super.onViewBound(view);
|
||||
NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
|
||||
prepareViews();
|
||||
}
|
||||
|
||||
private void prepareViews() {
|
||||
LinearLayoutManager layoutManager = new SmoothScrollLinearLayoutManager(getActivity());
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
prepareMenu();
|
||||
if (adapter == null) {
|
||||
adapter = new FlexibleAdapter<>(menuItems, getActivity(), false);
|
||||
}
|
||||
|
||||
adapter.addListener(this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void prepareIntent() {
|
||||
shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(getResources().getString(R.string.nc_share_subject),
|
||||
getResources().getString(R.string.nc_app_product_name)));
|
||||
}
|
||||
|
||||
private void prepareMenu() {
|
||||
menuItems = new ArrayList<>();
|
||||
|
||||
if (menuType.equals(MenuType.REGULAR)) {
|
||||
// if (!TextUtils.isEmpty(conversation.getDisplayName())) {
|
||||
// menuItems.add(new MenuItem(conversation.getDisplayName(), 0, null));
|
||||
// } else if (!TextUtils.isEmpty(conversation.getName())) {
|
||||
// menuItems.add(new MenuItem(conversation.getName(), 0, null));
|
||||
// } else {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_configure_room), 0, null));
|
||||
// }
|
||||
//
|
||||
// currentUser = userUtils.getCurrentUser();
|
||||
//
|
||||
// if (conversation.isFavorite()) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_remove_from_favorites), 97, DisplayUtils.getTintedDrawable(getResources(), R.drawable.ic_star_border_black_24dp, R.color.grey_600)));
|
||||
// } else if (CapabilitiesUtil.hasSpreedFeatureCapability(currentUser, "favorites")) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_add_to_favorites),
|
||||
// 98,
|
||||
// DisplayUtils.getTintedDrawable(getResources(),
|
||||
// R.drawable.ic_star_black_24dp,
|
||||
// R.color.grey_600)));
|
||||
// }
|
||||
//
|
||||
// if(conversation.unreadMessages > ALL_MESSAGES_READ && CapabilitiesUtil.canSetChatReadMarker(currentUser)) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_mark_as_read),
|
||||
// 96,
|
||||
// ContextCompat.getDrawable(context, R.drawable.ic_eye)));
|
||||
// }
|
||||
//
|
||||
// if (conversation.isNameEditable(currentUser)) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_rename),
|
||||
// 2,
|
||||
// ContextCompat.getDrawable(context,
|
||||
// R.drawable.ic_pencil_grey600_24dp)));
|
||||
// }
|
||||
//
|
||||
// if (conversation.canModerate(currentUser)) {
|
||||
// if (!conversation.isPublic()) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_make_call_public),
|
||||
// 3, ContextCompat.getDrawable(context,
|
||||
// R.drawable.ic_link_grey600_24px)));
|
||||
// } else {
|
||||
// if (conversation.isHasPassword()) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_change_password),
|
||||
// 4, ContextCompat.getDrawable(context,
|
||||
// R.drawable.ic_lock_grey600_24px)));
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_clear_password),
|
||||
// 5,
|
||||
// ContextCompat.getDrawable(context,
|
||||
// R.drawable.ic_lock_open_grey600_24dp)));
|
||||
// } else {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_set_password),
|
||||
// 6, ContextCompat.getDrawable(context,
|
||||
// R.drawable.ic_lock_plus_grey600_24dp)));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_delete_call),
|
||||
// 9, ContextCompat.getDrawable(context,
|
||||
// R.drawable.ic_delete_grey600_24dp)));
|
||||
// }
|
||||
//
|
||||
// if (conversation.isPublic()) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_share_link),
|
||||
// 7, ContextCompat.getDrawable(context,
|
||||
// R.drawable.ic_link_grey600_24px)));
|
||||
// if (conversation.canModerate(currentUser)) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_make_call_private),
|
||||
// 8, ContextCompat.getDrawable(context,
|
||||
// R.drawable.ic_group_grey600_24px)));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (conversation.canLeave(currentUser)) {
|
||||
// menuItems.add(new MenuItem(getResources().getString(R.string.nc_leave), 1,
|
||||
// DisplayUtils.getTintedDrawable(getResources(),
|
||||
// R.drawable.ic_exit_to_app_black_24dp, R.color.grey_600)
|
||||
// ));
|
||||
// }
|
||||
} else if (menuType.equals(MenuType.SHARE)) {
|
||||
prepareIntent();
|
||||
List<AppAdapter.AppInfo> appInfoList = ShareUtils.getShareApps(getActivity(), shareIntent, null,
|
||||
null);
|
||||
menuItems.add(new AppItem(getResources().getString(R.string.nc_share_link_via),
|
||||
"",
|
||||
"",
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_link_grey600_24px)));
|
||||
if (appInfoList != null) {
|
||||
for (AppAdapter.AppInfo appInfo : appInfoList) {
|
||||
menuItems.add(new AppItem(appInfo.title, appInfo.packageName, appInfo.name, appInfo.drawable));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
menuItems.add(new MenuItem(getResources().getString(R.string.nc_start_conversation), 0, null));
|
||||
menuItems.add(new MenuItem(getResources().getString(R.string.nc_new_conversation),
|
||||
1, ContextCompat.getDrawable(context,
|
||||
R.drawable.ic_add_grey600_24px)));
|
||||
menuItems.add(new MenuItem(getResources().getString(R.string.nc_join_via_link),
|
||||
2, ContextCompat.getDrawable(context,
|
||||
R.drawable.ic_link_grey600_24px)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(View view, int position) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation));
|
||||
|
||||
if (menuType.equals(MenuType.REGULAR)) {
|
||||
MenuItem menuItem = (MenuItem) adapter.getItem(position);
|
||||
if (menuItem != null) {
|
||||
|
||||
int tag = menuItem.getTag();
|
||||
if (tag == 5) {
|
||||
conversation.setPassword("");
|
||||
}
|
||||
|
||||
if (tag > 0) {
|
||||
if (tag == 1 || tag == 9) {
|
||||
if (tag == 1) {
|
||||
Data data;
|
||||
if ((data = getWorkerData()) != null) {
|
||||
OneTimeWorkRequest leaveConversationWorker =
|
||||
new OneTimeWorkRequest.Builder(LeaveConversationWorker.class).setInputData(data).build();
|
||||
WorkManager.getInstance().enqueue(leaveConversationWorker);
|
||||
}
|
||||
} else {
|
||||
Bundle deleteConversationBundle;
|
||||
if ((deleteConversationBundle = getDeleteConversationBundle()) != null) {
|
||||
conversationMenuInterface.openLovelyDialogWithIdAndBundle(ConversationsListController.ID_DELETE_CONVERSATION_DIALOG, deleteConversationBundle);
|
||||
}
|
||||
}
|
||||
eventBus.post(new BottomSheetLockEvent(true, 0, false, true));
|
||||
} else {
|
||||
|
||||
// TODO: continue here to extract more setOnClickListeners to ConversationOperationDialog.kt
|
||||
|
||||
bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), tag);
|
||||
if (tag != 2 && tag != 4 && tag != 6 && tag != 7) {
|
||||
// 3=make call public, 5=clear pw, 8=make call private ..
|
||||
eventBus.post(new BottomSheetLockEvent(false, 0, false, false));
|
||||
getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle))
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
} else if (tag != 7) {
|
||||
// 3=make call public, 5=clear pw, 8=make call private ..
|
||||
|
||||
// rename and set password !?
|
||||
getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle))
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
} else {
|
||||
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_MENU_TYPE(), Parcels.wrap(MenuType.SHARE));
|
||||
getRouter().pushController(RouterTransaction.with(new CallMenuController(bundle, null))
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (menuType.equals(MenuType.SHARE) && position != 0) {
|
||||
AppItem appItem = (AppItem) adapter.getItem(position);
|
||||
if (appItem != null && getActivity() != null) {
|
||||
if (!conversation.hasPassword) {
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, ShareUtils.getStringForIntent(getActivity(), null,
|
||||
userUtils, conversation));
|
||||
Intent intent = new Intent(shareIntent);
|
||||
intent.setComponent(new ComponentName(appItem.getPackageName(), appItem.getName()));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
eventBus.post(new BottomSheetLockEvent(true, 0, false, true));
|
||||
getActivity().startActivity(intent);
|
||||
} else {
|
||||
bundle.putInt(BundleKeys.INSTANCE.getKEY_OPERATION_CODE(), 7);
|
||||
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_SHARE_INTENT(), Parcels.wrap(shareIntent));
|
||||
bundle.putString(BundleKeys.INSTANCE.getKEY_APP_ITEM_PACKAGE_NAME(), appItem.getPackageName());
|
||||
bundle.putString(BundleKeys.INSTANCE.getKEY_APP_ITEM_NAME(), appItem.getName());
|
||||
getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle))
|
||||
.pushChangeHandler(new HorizontalChangeHandler())
|
||||
.popChangeHandler(new HorizontalChangeHandler()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Data getWorkerData() {
|
||||
if (!TextUtils.isEmpty(conversation.getToken())) {
|
||||
Data.Builder data = new Data.Builder();
|
||||
data.putString(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), conversation.getToken());
|
||||
data.putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), currentUser.getId());
|
||||
return data.build();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Bundle getDeleteConversationBundle() {
|
||||
if (!TextUtils.isEmpty(conversation.getToken())) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), currentUser.getId());
|
||||
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ROOM(), Parcels.wrap(conversation));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Parcel
|
||||
public enum MenuType {
|
||||
REGULAR, SHARE
|
||||
}
|
||||
}
|
@ -283,6 +283,23 @@ public class OperationsMenuController extends BaseController {
|
||||
int apiVersion = ApiUtils.getConversationApiVersion(currentUser, new int[] {ApiUtils.APIv4, ApiUtils.APIv1});
|
||||
int chatApiVersion = ApiUtils.getChatApiVersion(currentUser, new int[] {ApiUtils.APIv1});
|
||||
|
||||
|
||||
/*
|
||||
2: renameRoom
|
||||
3: make public
|
||||
4: change password
|
||||
5: clear password
|
||||
6: set password
|
||||
8: make private
|
||||
10: create conversation ??
|
||||
11: invite users to conversation
|
||||
96: set chat read marker
|
||||
97: remove favorite
|
||||
98: add favorite
|
||||
99: join room
|
||||
*/
|
||||
|
||||
|
||||
switch (operationCode) {
|
||||
case 2:
|
||||
ncApi.renameRoom(credentials, ApiUtils.getUrlForRoom(apiVersion, currentUser.getBaseUrl(),
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.nextcloud.talk.ui.dialog
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
@ -19,7 +20,6 @@ import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.controllers.ConversationsListController
|
||||
import com.nextcloud.talk.controllers.bottomsheet.CallMenuController
|
||||
import com.nextcloud.talk.controllers.bottomsheet.EntryMenuController
|
||||
import com.nextcloud.talk.controllers.bottomsheet.OperationsMenuController
|
||||
import com.nextcloud.talk.databinding.DialogConversationOperationsBinding
|
||||
@ -27,19 +27,14 @@ import com.nextcloud.talk.jobs.LeaveConversationWorker
|
||||
import com.nextcloud.talk.models.database.CapabilitiesUtil
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||
import com.nextcloud.talk.utils.ShareUtils
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_OPERATION_CODE
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils
|
||||
import org.parceler.Parcels
|
||||
import javax.inject.Inject
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.nextcloud.talk.utils.ShareUtils
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils
|
||||
import kotlinx.android.synthetic.main.activity_take_picture.*
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class ConversationOperationDialog(
|
||||
@ -96,8 +91,7 @@ class ConversationOperationDialog(
|
||||
)
|
||||
|
||||
binding.conversationOperationMarkAsRead.visibility = setVisibleIf(
|
||||
conversation.unreadMessages > CallMenuController.ALL_MESSAGES_READ
|
||||
&& CapabilitiesUtil.canSetChatReadMarker(currentUser)
|
||||
conversation.unreadMessages > 0 && CapabilitiesUtil.canSetChatReadMarker(currentUser)
|
||||
)
|
||||
|
||||
binding.conversationOperationRename.visibility = setVisibleIf(
|
||||
@ -248,7 +242,7 @@ class ConversationOperationDialog(
|
||||
.popChangeHandler(HorizontalChangeHandler())
|
||||
)
|
||||
|
||||
controller.fetchData(false)
|
||||
controller.fetchData()
|
||||
}
|
||||
|
||||
private fun executeEntryMenuController(operationCode: Int) {
|
||||
@ -266,6 +260,7 @@ class ConversationOperationDialog(
|
||||
// into EntryMenuController to execute fetch data... ?!)
|
||||
// for example if you set a password, the dialog items should be refreshed for the next time you open it
|
||||
// without to manually have to refresh the conversations list
|
||||
// also see BottomSheetLockEvent ??
|
||||
|
||||
RouterTransaction.with(EntryMenuController(bundle))
|
||||
.pushChangeHandler(HorizontalChangeHandler())
|
||||
|
@ -16,29 +16,19 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Part of the code in ShareUtils was inspired by BottomSheet under the Apache licence
|
||||
* located here: https://github.com/Kennyc1012/BottomSheet/blob/master/library/src/main/java/com/kennyc/bottomsheet/BottomSheet.java#L425
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.kennyc.bottomsheet.adapters.AppAdapter;
|
||||
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class ShareUtils {
|
||||
|
||||
@ -58,49 +48,4 @@ public class ShareUtils {
|
||||
|
||||
return shareString;
|
||||
}
|
||||
|
||||
public static List<AppAdapter.AppInfo> getShareApps(Context context, Intent intent,
|
||||
@Nullable Set<String> appsFilter, @Nullable Set<String> toExclude) {
|
||||
|
||||
if (context == null || intent == null) return null;
|
||||
|
||||
PackageManager manager = context.getPackageManager();
|
||||
List<ResolveInfo> apps = manager.queryIntentActivities(intent, 0);
|
||||
|
||||
if (apps != null && !apps.isEmpty()) {
|
||||
List<AppAdapter.AppInfo> appResources = new ArrayList<>(apps.size());
|
||||
boolean shouldCheckPackages = appsFilter != null && !appsFilter.isEmpty();
|
||||
|
||||
for (ResolveInfo resolveInfo : apps) {
|
||||
String packageName = resolveInfo.activityInfo.packageName;
|
||||
|
||||
if (shouldCheckPackages && !appsFilter.contains(packageName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String title = resolveInfo.loadLabel(manager).toString();
|
||||
String name = resolveInfo.activityInfo.name;
|
||||
Drawable drawable = resolveInfo.loadIcon(manager);
|
||||
appResources.add(new AppAdapter.AppInfo(title, packageName, name, drawable));
|
||||
}
|
||||
|
||||
if (toExclude != null && !toExclude.isEmpty()) {
|
||||
List<AppAdapter.AppInfo> toRemove = new ArrayList<>();
|
||||
|
||||
for (AppAdapter.AppInfo appInfo : appResources) {
|
||||
if (toExclude.contains(appInfo.packageName)) {
|
||||
toRemove.add(appInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (!toRemove.isEmpty()) appResources.removeAll(toRemove);
|
||||
}
|
||||
|
||||
return appResources;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user