mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #926 from deltachat/still-tweak-profile
still tweak profile
This commit is contained in:
@@ -225,10 +225,6 @@
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:finishOnTaskLaunch="true" />
|
||||
|
||||
<activity android:name=".RecipientPreferenceActivity"
|
||||
android:theme="@style/TextSecure.LightNoActionBar"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".BlockedAndShareContactsActivity"
|
||||
android:theme="@style/TextSecure.LightTheme"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:interpolator="@android:anim/decelerate_interpolator">
|
||||
<alpha
|
||||
android:duration="150"
|
||||
android:fromAlpha="0.3"
|
||||
android:toAlpha="1.0" />
|
||||
</set>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:interpolator="@android:anim/decelerate_interpolator">
|
||||
<alpha
|
||||
android:duration="150"
|
||||
android:fromAlpha="1.0"
|
||||
android:toAlpha="0.3" />
|
||||
</set>
|
||||
@@ -4,7 +4,7 @@
|
||||
>
|
||||
|
||||
<item android:title="@string/menu_view_profile"
|
||||
android:id="@+id/menu_conversation_settings"/>
|
||||
android:id="@+id/menu_profile"/>
|
||||
|
||||
<item android:title="@string/menu_add_attachment"
|
||||
android:id="@+id/menu_add_attachment" />
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:id="@+id/menu_edit_group"
|
||||
android:title="@string/menu_edit_group" />
|
||||
|
||||
<item android:id="@+id/menu_leave"
|
||||
android:title="@string/menu_leave_group"
|
||||
app:showAsAction="collapseActionView"/>
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:title="@string/menu_edit_group_image"
|
||||
android:id="@+id/edit_group_image"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item android:title="@string/menu_mute"
|
||||
android:id="@+id/menu_mute_notifications"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<!-- android:icon="@drawable/ic_create_white_24dp" app:showAsAction="always" is not needed as the image is already shown
|
||||
and editing group images and names is not an action that is used every time the profile is opened -->
|
||||
<item android:title="@string/menu_group_name_and_image"
|
||||
android:id="@+id/edit_name_etc"
|
||||
<item android:title="@string/menu_edit_name"
|
||||
android:id="@+id/edit_name"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
||||
|
||||
@@ -145,6 +145,8 @@
|
||||
<string name="menu_select_all">Select all</string>
|
||||
<string name="menu_expand">Expand</string>
|
||||
<string name="menu_edit_name">Edit name</string>
|
||||
<string name="menu_edit_group_name">Edit group name</string>
|
||||
<string name="menu_edit_group_image">Edit group image</string>
|
||||
<string name="menu_settings">Settings</string>
|
||||
<string name="menu_advanced">Advanced</string>
|
||||
<string name="menu_deaddrop">Contact requests</string>
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<PreferenceCategory android:key="contact_info" android:title="@string/contact">
|
||||
|
||||
<Preference android:key="pref_key_recipient_addr"
|
||||
android:title="user@example.org"
|
||||
android:persistent="false"/>
|
||||
|
||||
<Preference android:key="pref_key_new_chat"
|
||||
android:title="@string/menu_new_chat"
|
||||
android:persistent="false"/>
|
||||
|
||||
<Preference android:key="pref_key_recipient_edit_name"
|
||||
android:title="@string/menu_edit_name"
|
||||
android:persistent="false"/>
|
||||
|
||||
<Preference android:key="pref_key_recipient_encryption_info"
|
||||
android:title="@string/profile_encryption"
|
||||
android:persistent="false"/>
|
||||
|
||||
<Preference android:key="pref_key_recipient_block"
|
||||
android:title="@string/menu_block_contact"
|
||||
android:persistent="false"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:key="contact_divider" android:layout="@layout/preference_divider"/>
|
||||
|
||||
<PreferenceCategory android:key="notification_settings" android:title="@string/pref_chat_settings">
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:key="pref_key_recipient_mute"
|
||||
android:title="@string/menu_mute"
|
||||
android:defaultValue="false"
|
||||
android:disableDependentsState="true"
|
||||
android:persistent="false" />
|
||||
|
||||
<org.thoughtcrime.securesms.preferences.widgets.SignalPreference
|
||||
android:dependency="pref_key_recipient_mute"
|
||||
android:key="pref_key_recipient_ringtone"
|
||||
android:title="@string/pref_sound"
|
||||
android:persistent="false"/>
|
||||
|
||||
<org.thoughtcrime.securesms.preferences.widgets.ListPreferenceWithSummary
|
||||
android:dependency="pref_key_recipient_mute"
|
||||
android:key="pref_key_recipient_vibrate"
|
||||
android:title="@string/pref_vibrate"
|
||||
android:entries="@array/recipient_vibrate_entries"
|
||||
android:entryValues="@array/recipient_vibrate_values"
|
||||
android:defaultValue="0"
|
||||
android:persistent="false"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -470,13 +470,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
super.onOptionsItemSelected(item);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_add_attachment: handleAddAttachment(); return true;
|
||||
case R.id.menu_edit_group: handleEditPushGroup(); return true;
|
||||
case R.id.menu_leave: handleLeaveGroup(); return true;
|
||||
case R.id.menu_archive_chat: handleArchiveChat(); return true;
|
||||
case R.id.menu_delete_chat: handleDeleteChat(); return true;
|
||||
case R.id.menu_mute_notifications: handleMuteNotifications(); return true;
|
||||
case R.id.menu_unmute_notifications: handleUnmuteNotifications(); return true;
|
||||
case R.id.menu_conversation_settings: handleConversationSettings(); return true;
|
||||
case R.id.menu_profile: handleProfile(); return true;
|
||||
case R.id.menu_show_map: handleShowMap(); return true;
|
||||
case android.R.id.home: handleReturnToConversationList(); return true;
|
||||
}
|
||||
@@ -541,16 +540,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
if(chatId != DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
Intent intent = new Intent(this, ProfileActivity.class);
|
||||
intent.putExtra(ProfileActivity.CHAT_ID_EXTRA, chatId);
|
||||
intent.putExtra(ProfileActivity.FROM_CHAT, true);
|
||||
startActivity(intent);
|
||||
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleConversationSettings() {
|
||||
if(chatId != DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
Intent intent = new Intent(ConversationActivity.this, RecipientPreferenceActivity.class);
|
||||
intent.putExtra(RecipientPreferenceActivity.ADDRESS_EXTRA, recipient.getAddress());
|
||||
startActivitySceneTransition(intent, titleView.findViewById(R.id.contact_photo_image), "avatar");
|
||||
overridePendingTransition(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,15 +583,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
.show();
|
||||
}
|
||||
|
||||
private void handleEditPushGroup() {
|
||||
Intent intent = new Intent(ConversationActivity.this, GroupCreateActivity.class);
|
||||
intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, chatId);
|
||||
if (dcChat.isVerified()) {
|
||||
intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, true);
|
||||
}
|
||||
startActivityForResult(intent, GROUP_EDIT);
|
||||
}
|
||||
|
||||
private void handleAddAttachment() {
|
||||
if (attachmentTypeSelector == null) {
|
||||
attachmentTypeSelector = new AttachmentTypeSelector(this, getSupportLoaderManager(), new AttachmentTypeListener(), chatId);
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcContact;
|
||||
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
@@ -52,15 +53,18 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
}
|
||||
|
||||
public void setTitle(@NonNull GlideRequests glideRequests, @Nullable DcChat dcChat) {
|
||||
setTitle(glideRequests, dcChat, true);
|
||||
}
|
||||
|
||||
public void setTitle(@NonNull GlideRequests glideRequests, @Nullable DcChat dcChat, boolean showSubtitle) {
|
||||
|
||||
int imgLeft = 0;
|
||||
int imgRight = 0;
|
||||
//int imgSubtitleRight = 0;
|
||||
|
||||
if (dcChat == null) {
|
||||
setComposeTitle();
|
||||
} else {
|
||||
setRecipientTitle(dcChat);
|
||||
setRecipientTitle(dcChat, showSubtitle);
|
||||
if (Prefs.isChatMuted(getContext(), dcChat.getId())) {
|
||||
imgLeft = R.drawable.ic_volume_off_white_18dp;
|
||||
}
|
||||
@@ -68,14 +72,18 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
imgRight = R.drawable.ic_verified;
|
||||
}
|
||||
this.avatar.setAvatar(glideRequests, DcHelper.getContext(getContext()).getRecipient(dcChat), false);
|
||||
|
||||
//if (dcChat.isSendingLocations()) {
|
||||
// imgSubtitleRight = R.drawable.ic_location_chatlist;
|
||||
//}
|
||||
}
|
||||
|
||||
title.setCompoundDrawablesWithIntrinsicBounds(imgLeft, 0, imgRight, 0);
|
||||
//subtitle.setCompoundDrawablesWithIntrinsicBounds(0, 0, imgSubtitleRight, 0);
|
||||
}
|
||||
|
||||
public void setTitle(@NonNull GlideRequests glideRequests, @Nullable DcContact contact) {
|
||||
// the verified state is _not_ shown in the title. this will be confusing as in the one-to-one-ChatViews, the verified
|
||||
// icon is also not shown as these chats are always opportunistic chats
|
||||
avatar.setAvatar(glideRequests, DcHelper.getContext(getContext()).getRecipient(contact), false);
|
||||
title.setText(contact.getDisplayName());
|
||||
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
subtitle.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void hideAvatar() {
|
||||
@@ -88,6 +96,10 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
this.avatar.setOnClickListener(listener);
|
||||
}
|
||||
|
||||
public void setOnAvatarClickListener(@Nullable OnClickListener listener) {
|
||||
this.avatar.setOnClickListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnLongClickListener(@Nullable OnLongClickListener listener) {
|
||||
this.content.setOnLongClickListener(listener);
|
||||
@@ -104,7 +116,7 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
this.subtitle.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void setRecipientTitle(DcChat dcChat) {
|
||||
private void setRecipientTitle(DcChat dcChat, boolean showSubtitle) {
|
||||
|
||||
if(dcChat.getId()==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
this.title.setText(R.string.menu_deaddrop);
|
||||
@@ -115,6 +127,6 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
this.subtitle.setText(dcChat.getSubtitle());
|
||||
}
|
||||
|
||||
this.subtitle.setVisibility(View.VISIBLE);
|
||||
this.subtitle.setVisibility(showSubtitle? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,3 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* 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 org.thoughtcrime.securesms;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -34,7 +17,6 @@ import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
@@ -66,17 +48,10 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Activity to create and update groups
|
||||
*
|
||||
* @author Jake McGinty
|
||||
*/
|
||||
public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
implements OnRecipientDeletedListener, DcEventCenter.DcEventDelegate
|
||||
{
|
||||
|
||||
private final static String TAG = GroupCreateActivity.class.getSimpleName();
|
||||
|
||||
public static final String EDIT_GROUP_CHAT_ID = "edit_group_chat_id";
|
||||
public static final String GROUP_CREATE_VERIFIED_EXTRA = "group_create_verified";
|
||||
|
||||
@@ -92,7 +67,6 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
private EditText groupName;
|
||||
private ListView lv;
|
||||
private ImageView avatar;
|
||||
private TextView creatingText;
|
||||
private Bitmap avatarBmp;
|
||||
private int groupChatId;
|
||||
private boolean isEdit;
|
||||
@@ -123,8 +97,8 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
initializeExistingGroup();
|
||||
initializeResources();
|
||||
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_CHAT_MODIFIED);
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_CONTACTS_CHANGED);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CHAT_MODIFIED, this);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,7 +190,6 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
lv = ViewUtil.findById(this, R.id.selected_contacts_list);
|
||||
avatar = ViewUtil.findById(this, R.id.avatar);
|
||||
groupName = ViewUtil.findById(this, R.id.group_name);
|
||||
creatingText = ViewUtil.findById(this, R.id.creating_group_text);
|
||||
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this);
|
||||
adapter.setOnRecipientDeletedListener(this);
|
||||
lv.setAdapter(adapter);
|
||||
@@ -224,6 +197,12 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
findViewById(R.id.add_member_button).setOnClickListener(new AddRecipientButtonListener());
|
||||
ViewUtil.findById(this, R.id.verify_button).setOnClickListener(new ShowQrButtonListener());
|
||||
initializeAvatarView();
|
||||
|
||||
if(isEdit()) {
|
||||
lv.setVisibility(View.GONE);
|
||||
findViewById(R.id.add_member_button).setVisibility(View.GONE);
|
||||
findViewById( R.id.verify_button).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeAvatarView() {
|
||||
@@ -507,6 +486,9 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
if (!isFinishing()) {
|
||||
addSelectedContacts(participantsArray);
|
||||
groupName.setText(recipient.getName());
|
||||
if (isEdit() && recipient.getName()!=null) {
|
||||
groupName.setSelection(recipient.getName().length(), recipient.getName().length());
|
||||
}
|
||||
SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this, participants);
|
||||
adapter.setOnRecipientDeletedListener(this);
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
@@ -25,6 +26,7 @@ import com.b44t.messenger.DcEventCenter;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
@@ -32,7 +34,6 @@ import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
implements DcEventCenter.DcEventDelegate
|
||||
@@ -44,6 +45,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
public static final String CHAT_ID_EXTRA = "chat_id";
|
||||
public static final String CONTACT_ID_EXTRA = "contact_id";
|
||||
public static final String FORCE_TAB_EXTRA = "force_tab";
|
||||
public static final String FROM_CHAT = "from_chat";
|
||||
|
||||
public static final int TAB_SETTINGS = 10;
|
||||
public static final int TAB_GALLERY = 20;
|
||||
@@ -60,9 +62,11 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
private int chatId;
|
||||
private boolean chatIsGroup;
|
||||
private int contactId;
|
||||
private boolean fromChat;
|
||||
|
||||
private ArrayList<Integer> tabs = new ArrayList<>();
|
||||
private Toolbar toolbar;
|
||||
private ConversationTitleView titleView;
|
||||
private TabLayout tabLayout;
|
||||
private ViewPager viewPager;
|
||||
|
||||
@@ -78,7 +82,19 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
setContentView(R.layout.profile_activity);
|
||||
|
||||
initializeResources();
|
||||
initializeToolbar();
|
||||
|
||||
setSupportActionBar(this.toolbar);
|
||||
ActionBar supportActionBar = getSupportActionBar();
|
||||
supportActionBar.setDisplayHomeAsUpEnabled(false);
|
||||
supportActionBar.setCustomView(R.layout.conversation_title_view);
|
||||
supportActionBar.setDisplayShowCustomEnabled(true);
|
||||
supportActionBar.setDisplayShowTitleEnabled(false);
|
||||
|
||||
titleView = (ConversationTitleView) supportActionBar.getCustomView();
|
||||
titleView.setOnBackClickedListener(view -> onBackPressed());
|
||||
titleView.setOnAvatarClickListener(view -> onShowAndEditImage());
|
||||
|
||||
updateToolbar();
|
||||
|
||||
this.tabLayout.setupWithViewPager(viewPager);
|
||||
this.viewPager.setAdapter(new ProfilePagerAdapter(getSupportFragmentManager()));
|
||||
@@ -91,13 +107,16 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
|
||||
inflater.inflate(R.menu.profile_common, menu);
|
||||
if (!chatIsGroup) {
|
||||
menu.findItem(R.id.edit_name_etc).setTitle(R.string.menu_edit_name);
|
||||
}
|
||||
|
||||
if (!isSelfProfile()) {
|
||||
if (chatId != 0) {
|
||||
inflater.inflate(R.menu.profile_chat, menu);
|
||||
if (chatIsGroup) {
|
||||
menu.findItem(R.id.edit_name).setTitle(R.string.menu_edit_group_name);
|
||||
}
|
||||
else {
|
||||
menu.findItem(R.id.edit_group_image).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (isContactProfile()) {
|
||||
@@ -132,6 +151,21 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
dynamicLanguage.onResume(this);
|
||||
}
|
||||
|
||||
boolean backPressed = false;
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
backPressed = true;
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (backPressed && fromChat) {
|
||||
overridePendingTransition(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
dcContext.eventCenter.removeObservers(this);
|
||||
@@ -147,6 +181,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
chatId = getIntent().getIntExtra(CHAT_ID_EXTRA, 0);
|
||||
contactId = getIntent().getIntExtra(CONTACT_ID_EXTRA, 0);
|
||||
chatIsGroup = false;
|
||||
fromChat = getIntent().getBooleanExtra(FROM_CHAT, false);
|
||||
|
||||
if (contactId!=0) {
|
||||
chatId = dcContext.getChatIdByContactId(contactId);
|
||||
@@ -175,22 +210,16 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
this.tabLayout = ViewUtil.findById(this, R.id.tab_layout);
|
||||
}
|
||||
|
||||
private void initializeToolbar()
|
||||
{
|
||||
setSupportActionBar(this.toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
updateToolbar();
|
||||
}
|
||||
|
||||
private void updateToolbar() {
|
||||
if (isGlobalProfile()){
|
||||
getSupportActionBar().setTitle(R.string.menu_all_media);
|
||||
}
|
||||
else if (isContactProfile()){
|
||||
getSupportActionBar().setTitle(dcContext.getContact(contactId).getName());
|
||||
else if (chatId > 0) {
|
||||
DcChat dcChat = dcContext.getChat(chatId);
|
||||
titleView.setTitle(GlideApp.with(this), dcChat, false);
|
||||
}
|
||||
else if (chatId >= 0) {
|
||||
getSupportActionBar().setTitle(dcContext.getChat(chatId).getName());
|
||||
else if (isContactProfile()){
|
||||
titleView.setTitle(GlideApp.with(this), dcContext.getContact(contactId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +287,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
return getString(contactId==DcContact.DC_CONTACT_ID_SELF? R.string.self : R.string.tab_contact);
|
||||
}
|
||||
else {
|
||||
return getString(R.string.tab_members);
|
||||
return getString(R.string.tab_group);
|
||||
}
|
||||
|
||||
case TAB_GALLERY:
|
||||
@@ -289,6 +318,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
backPressed = true;
|
||||
finish();
|
||||
return true;
|
||||
case R.id.menu_mute_notifications:
|
||||
@@ -300,13 +330,11 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
case R.id.menu_vibrate:
|
||||
onVibrateSettings();
|
||||
break;
|
||||
case R.id.edit_name_etc:
|
||||
if (chatIsGroup) {
|
||||
onEditGroupNameAndImage();
|
||||
}
|
||||
else {
|
||||
onEditContactName();
|
||||
}
|
||||
case R.id.edit_name:
|
||||
onEditName();
|
||||
break;
|
||||
case R.id.edit_group_image:
|
||||
onShowAndEditImage();
|
||||
break;
|
||||
case R.id.show_encr_info:
|
||||
onEncrInfo();
|
||||
@@ -365,28 +393,35 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
.show();
|
||||
}
|
||||
|
||||
public void onEditGroupNameAndImage() {
|
||||
Intent intent = new Intent(this, GroupCreateActivity.class);
|
||||
intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, chatId);
|
||||
if (dcContext.getChat(chatId).isVerified()) {
|
||||
intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, true);
|
||||
public void onShowAndEditImage() {
|
||||
if (chatIsGroup) {
|
||||
Intent intent = new Intent(this, GroupCreateActivity.class);
|
||||
intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, chatId);
|
||||
if (dcContext.getChat(chatId).isVerified()) {
|
||||
intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, true);
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void onEditContactName() {
|
||||
DcContact dcContact = dcContext.getContact(contactId);
|
||||
final EditText txt = new EditText(this);
|
||||
txt.setText(dcContact.getName());
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.menu_edit_name)
|
||||
.setView(txt)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> {
|
||||
String newName = txt.getText().toString();
|
||||
dcContext.createContact(newName, dcContact.getAddr());
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
public void onEditName() {
|
||||
if (chatIsGroup) {
|
||||
onShowAndEditImage();
|
||||
}
|
||||
else {
|
||||
DcContact dcContact = dcContext.getContact(contactId);
|
||||
final EditText txt = new EditText(this);
|
||||
txt.setText(dcContact.getName());
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.menu_edit_name)
|
||||
.setView(txt)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> {
|
||||
String newName = txt.getText().toString();
|
||||
dcContext.createContact(newName, dcContact.getAddr());
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
public void onEncrInfo() {
|
||||
|
||||
@@ -2,8 +2,6 @@ package org.thoughtcrime.securesms;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -19,7 +17,6 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
@@ -31,7 +28,6 @@ import com.b44t.messenger.DcEventCenter;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
@@ -139,7 +135,7 @@ public class ProfileSettingsFragment extends Fragment
|
||||
onNewChat();
|
||||
break;
|
||||
case ProfileSettingsAdapter.SETTING_CONTACT_NAME:
|
||||
((ProfileActivity)getActivity()).onEditContactName();
|
||||
((ProfileActivity)getActivity()).onEditName();
|
||||
break;
|
||||
case ProfileSettingsAdapter.SETTING_ENCRYPTION:
|
||||
((ProfileActivity)getActivity()).onEncrInfo();
|
||||
|
||||
@@ -1,574 +0,0 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.CollapsingToolbarLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.preference.CheckBoxPreference;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcEventCenter;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.Prefs.VibrateState;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActivity implements DcEventCenter.DcEventDelegate
|
||||
{
|
||||
private static final String TAG = RecipientPreferenceActivity.class.getSimpleName();
|
||||
|
||||
public static final String ADDRESS_EXTRA = "recipient_address";
|
||||
|
||||
private static final String PREFERENCE_MUTED = "pref_key_recipient_mute";
|
||||
private static final String PREFERENCE_MESSAGE_TONE = "pref_key_recipient_ringtone";
|
||||
private static final String PREFERENCE_MESSAGE_VIBRATE = "pref_key_recipient_vibrate";
|
||||
private static final String PREFERENCE_BLOCK = "pref_key_recipient_block";
|
||||
private static final String PREFERENCE_ENCRYPTION = "pref_key_recipient_encryption_info";
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
private ImageView avatar;
|
||||
private GlideRequests glideRequests;
|
||||
private Address address;
|
||||
private CollapsingToolbarLayout toolbarLayout;
|
||||
|
||||
private ApplicationDcContext dcContext;
|
||||
|
||||
private static final int REQUEST_CODE_PICK_RINGTONE = 1;
|
||||
|
||||
@Override
|
||||
public void onPreCreate() {
|
||||
dynamicTheme.onCreate(this);
|
||||
dynamicLanguage.onCreate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle instanceState, boolean ready) {
|
||||
dcContext = DcHelper.getContext(this);
|
||||
|
||||
setContentView(R.layout.recipient_preference_activity);
|
||||
this.glideRequests = GlideApp.with(this);
|
||||
this.address = getIntent().getParcelableExtra(ADDRESS_EXTRA);
|
||||
|
||||
Recipient recipient = Recipient.from(this, address);
|
||||
|
||||
initializeToolbar();
|
||||
setHeader(recipient);
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(ADDRESS_EXTRA, address);
|
||||
initFragment(R.id.preference_fragment, new RecipientPreferenceFragment(), null, bundle);
|
||||
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
dcContext.eventCenter.removeObservers(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
dynamicTheme.onResume(this);
|
||||
dynamicLanguage.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.preference_fragment);
|
||||
fragment.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(int eventId, Object data1, Object data2) {
|
||||
if(eventId==DcContext.DC_EVENT_CONTACTS_CHANGED) {
|
||||
Recipient recipient = Recipient.from(this, address);
|
||||
setHeader(recipient);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
finish();
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
||||
}
|
||||
|
||||
private void initializeToolbar() {
|
||||
this.toolbarLayout = ViewUtil.findById(this, R.id.collapsing_toolbar);
|
||||
this.avatar = ViewUtil.findById(this, R.id.avatar);
|
||||
|
||||
this.toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.white));
|
||||
this.toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.white));
|
||||
|
||||
Toolbar toolbar = ViewUtil.findById(this, R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setLogo(null);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
|
||||
private void setHeader(@NonNull Recipient recipient) {
|
||||
glideRequests.load(recipient.getContactPhoto(this))
|
||||
.fallback(recipient.getFallbackContactPhoto().asCallCard(this))
|
||||
.error(recipient.getFallbackContactPhoto().asCallCard(this))
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.into(this.avatar);
|
||||
|
||||
if (recipient.getContactPhoto(this) == null) this.avatar.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
|
||||
this.avatar.setBackgroundColor(recipient.getFallbackAvatarColor(this));
|
||||
this.toolbarLayout.setTitle(recipient.toShortString());
|
||||
this.toolbarLayout.setContentScrimColor(recipient.getFallbackAvatarColor(this));
|
||||
}
|
||||
|
||||
|
||||
// the fragment
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static class RecipientPreferenceFragment
|
||||
extends CorrectedPreferenceFragment
|
||||
implements DcEventCenter.DcEventDelegate
|
||||
{
|
||||
private ApplicationDcContext dcContext;
|
||||
private Recipient profileRecipient; // the recipient the profile was opened for, may be a chat or a contact
|
||||
private DcChat chatToEdit; // may be an invalid chat that returns 0 as id
|
||||
private Recipient chatToEditRecipient;
|
||||
private Recipient contactToEditRecipient;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
dcContext = DcHelper.getContext(getActivity());
|
||||
profileRecipient = Recipient.from(getActivity(), getArguments().getParcelable(ADDRESS_EXTRA));
|
||||
|
||||
|
||||
// set the recipient to edit as the chat.
|
||||
// when the profile shows a contact, this is _not_ the contact but the chat with the contact (if exists)
|
||||
int chatToEditId = profileRecipient.getAddress().isDcChat()? profileRecipient.getAddress().getDcChatId() : 0;
|
||||
if(chatToEditId==0 && profileRecipient.getAddress().isDcContact()) {
|
||||
chatToEditId = dcContext.getChatIdByContactId(profileRecipient.getAddress().getDcContactId());
|
||||
}
|
||||
chatToEdit = dcContext.getChat(chatToEditId);
|
||||
chatToEditRecipient = Recipient.from(getActivity(), Address.fromChat(chatToEditId));
|
||||
|
||||
// set the recipent really to edit as the contact
|
||||
int contactToEditId = profileRecipient.getAddress().isDcContact()? profileRecipient.getAddress().getDcContactId() : 0;
|
||||
if(contactToEditId==0 && !chatToEdit.isGroup() ) {
|
||||
int members[] = dcContext.getChatContacts(chatToEdit.getId());
|
||||
if(members.length>=1) {
|
||||
contactToEditId = members[0];
|
||||
}
|
||||
}
|
||||
contactToEditRecipient = Recipient.from(getActivity(), Address.fromContact(contactToEditId));
|
||||
|
||||
|
||||
this.findPreference(PREFERENCE_MESSAGE_TONE)
|
||||
.setOnPreferenceChangeListener(new RingtoneChangeListener());
|
||||
this.findPreference(PREFERENCE_MESSAGE_TONE)
|
||||
.setOnPreferenceClickListener(new RingtoneClickedListener());
|
||||
this.findPreference(PREFERENCE_MESSAGE_VIBRATE)
|
||||
.setOnPreferenceChangeListener(new VibrateChangeListener());
|
||||
this.findPreference(PREFERENCE_MUTED)
|
||||
.setOnPreferenceClickListener(new MuteClickedListener());
|
||||
this.findPreference(PREFERENCE_BLOCK)
|
||||
.setOnPreferenceClickListener(new BlockClickedListener());
|
||||
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
|
||||
Log.w(TAG, "onCreatePreferences...");
|
||||
addPreferencesFromResource(R.xml.recipient_preferences);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
||||
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setSummaries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
dcContext.eventCenter.removeObservers(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_CODE_PICK_RINGTONE && resultCode == RESULT_OK && data != null) {
|
||||
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||
|
||||
findPreference(PREFERENCE_MESSAGE_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_MESSAGE_TONE), uri);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSummaries() {
|
||||
|
||||
// chat settings
|
||||
PreferenceCategory notificationCategory = (PreferenceCategory)this.findPreference("notification_settings");
|
||||
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
|
||||
Preference ringtoneMessagePreference = this.findPreference(PREFERENCE_MESSAGE_TONE);
|
||||
ListPreference vibrateMessagePreference = (ListPreference) this.findPreference(PREFERENCE_MESSAGE_VIBRATE);
|
||||
|
||||
// contact settings
|
||||
PreferenceCategory contactInfoCategory = (PreferenceCategory) this.findPreference("contact_info");
|
||||
PreferenceCategory contactInfoDivider = (PreferenceCategory) this.findPreference("contact_divider");
|
||||
Preference addrPreference = this.findPreference("pref_key_recipient_addr");
|
||||
Preference encryptionPreference = this.findPreference(PREFERENCE_ENCRYPTION);
|
||||
Preference editNamePreference = this.findPreference("pref_key_recipient_edit_name");
|
||||
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
|
||||
Preference newChatPreference = this.findPreference("pref_key_new_chat");
|
||||
|
||||
|
||||
editNamePreference.setOnPreferenceClickListener(new EditContactNameListener());
|
||||
encryptionPreference.setOnPreferenceClickListener(new ShowEncrInfoListener());
|
||||
|
||||
mutePreference.setChecked(Prefs.isChatMuted(getContext(), chatToEdit.getId()));
|
||||
|
||||
ringtoneMessagePreference.setSummary(getRingtoneSummary(getContext(), chatToEditRecipient.getMessageRingtone()));
|
||||
|
||||
VibrateState vibrateState = Prefs.getChatVibrate(getContext(), chatToEdit.getId());
|
||||
Pair<String, Integer> vibrateMessageSummary = getVibrateSummary(getContext(), vibrateState);
|
||||
|
||||
vibrateMessagePreference.setSummary(vibrateMessageSummary.first);
|
||||
vibrateMessagePreference.setValueIndex(vibrateMessageSummary.second);
|
||||
|
||||
if (chatToEdit.getId()!=0 && chatToEdit.isGroup()) {
|
||||
// group
|
||||
if (contactInfoCategory != null) contactInfoCategory.setVisible(false);
|
||||
if (addrPreference != null) addrPreference.setVisible(false);
|
||||
if (encryptionPreference != null) encryptionPreference.setVisible(false);
|
||||
if (editNamePreference != null) editNamePreference.setVisible(false); // group name is currently somewhere else ...
|
||||
if (blockPreference != null) blockPreference.setVisible(false);
|
||||
if (newChatPreference != null) newChatPreference.setVisible(false);
|
||||
|
||||
if (contactInfoDivider != null) contactInfoDivider.setVisible(false);
|
||||
}
|
||||
else {
|
||||
// contact view
|
||||
DcContact contact = getProfileContact();
|
||||
String address = contact.getAddr();
|
||||
addrPreference.setTitle(address);
|
||||
addrPreference.setOnPreferenceClickListener(preference -> {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(address)
|
||||
.setItems(new CharSequence[]{
|
||||
getContext().getString(R.string.menu_copy_to_clipboard)
|
||||
},
|
||||
(dialogInterface, i) -> {
|
||||
Util.writeTextToClipboard(getContext(), address);
|
||||
Toast.makeText(getContext(), getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
return false;
|
||||
});
|
||||
|
||||
newChatPreference.setOnPreferenceClickListener(preference -> {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(getActivity().getString(R.string.ask_start_chat_with, contact.getNameNAddr()))
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
int chatId = dcContext.createChatByContactId(contact.getId());
|
||||
if (chatId != 0) {
|
||||
Intent intent = new Intent(getActivity(), ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
getActivity().startActivity(intent);
|
||||
getActivity().finish();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
return false;
|
||||
});
|
||||
|
||||
if (contactToEditRecipient.isBlocked()) blockPreference.setTitle(R.string.menu_unblock_contact);
|
||||
else blockPreference.setTitle(R.string.menu_block_contact);
|
||||
|
||||
if(chatToEdit.getId()==0) {
|
||||
mutePreference.setVisible(false);
|
||||
ringtoneMessagePreference.setVisible(false);
|
||||
vibrateMessagePreference.setVisible(false);
|
||||
notificationCategory.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DcContact getProfileContact() {
|
||||
if(profileRecipient.getAddress().isDcContact()) {
|
||||
return dcContext.getContact(profileRecipient.getAddress().getDcContactId());
|
||||
}
|
||||
else if(profileRecipient.getAddress().isDcChat()) {
|
||||
int members[] = dcContext.getChatContacts(profileRecipient.getAddress().getDcChatId());
|
||||
if(members.length>=1) {
|
||||
return dcContext.getContact(members[0]);
|
||||
}
|
||||
}
|
||||
return dcContext.getContact(0);
|
||||
}
|
||||
|
||||
private @NonNull String getRingtoneSummary(@NonNull Context context, @Nullable Uri ringtone) {
|
||||
if (ringtone == null) {
|
||||
return context.getString(R.string.def);
|
||||
} else if (ringtone.toString().isEmpty()) {
|
||||
return context.getString(R.string.pref_silent);
|
||||
} else {
|
||||
Ringtone tone = RingtoneManager.getRingtone(getActivity(), ringtone);
|
||||
|
||||
if (tone != null) {
|
||||
return tone.getTitle(context);
|
||||
}
|
||||
}
|
||||
|
||||
return context.getString(R.string.def);
|
||||
}
|
||||
|
||||
private @NonNull Pair<String, Integer> getVibrateSummary(@NonNull Context context, @NonNull VibrateState vibrateState) {
|
||||
if (vibrateState == VibrateState.DEFAULT) {
|
||||
return new Pair<>(context.getString(R.string.def), 0);
|
||||
} else if (vibrateState == VibrateState.ENABLED) {
|
||||
return new Pair<>(context.getString(R.string.on), 1);
|
||||
} else {
|
||||
return new Pair<>(context.getString(R.string.off), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(int eventId, Object data1, Object data2) {
|
||||
if(eventId==DcContext.DC_EVENT_CONTACTS_CHANGED) {
|
||||
setSummaries();
|
||||
}
|
||||
}
|
||||
|
||||
private class RingtoneChangeListener implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
RingtoneChangeListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Uri value = (Uri)newValue;
|
||||
|
||||
Uri defaultValue = Prefs.getNotificationRingtone(getContext());
|
||||
|
||||
if (defaultValue.equals(value)) value = null;
|
||||
else if (value == null) value = Uri.EMPTY;
|
||||
|
||||
Prefs.setChatRingtone(getContext(), chatToEdit.getId(), value);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class RingtoneClickedListener implements Preference.OnPreferenceClickListener {
|
||||
|
||||
RingtoneClickedListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Uri current = chatToEditRecipient.getMessageRingtone();
|
||||
Uri defaultUri = Prefs.getNotificationRingtone(getContext());
|
||||
|
||||
if (current == null) current = Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||
else if (current.toString().isEmpty()) current = null;
|
||||
|
||||
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, defaultUri);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current);
|
||||
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class VibrateChangeListener implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
VibrateChangeListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int value = Integer.parseInt((String) newValue);
|
||||
final VibrateState vibrateState = VibrateState.fromId(value);
|
||||
|
||||
Prefs.setChatVibrate(getContext(), chatToEdit.getId(), vibrateState);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class MuteClickedListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (Prefs.isChatMuted(getContext(), chatToEdit.getId())) {
|
||||
handleUnmute();
|
||||
}
|
||||
else {
|
||||
handleMute();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleMute() {
|
||||
MuteDialog.show(getActivity(), until -> setMuted(until));
|
||||
}
|
||||
|
||||
private void handleUnmute() {
|
||||
setMuted(0);
|
||||
}
|
||||
|
||||
private void setMuted(final long until) {
|
||||
if(chatToEditRecipient.getAddress().isDcChat()) {
|
||||
Prefs.setChatMutedUntil(getActivity(), chatToEditRecipient.getAddress().getDcChatId(), until);
|
||||
setSummaries();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ShowEncrInfoListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String info_str = dcContext.getContactEncrInfo(contactToEditRecipient.getAddress().getDcContactId());
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(info_str)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class EditContactNameListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
final DcContact dcContact = dcContext.getContact(contactToEditRecipient.getAddress().getDcContactId());
|
||||
final EditText txt = new EditText(getActivity());
|
||||
txt.setText(dcContact.getName());
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.menu_edit_name)
|
||||
.setView(txt)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> {
|
||||
String newName = txt.getText().toString();
|
||||
dcContext.createContact(newName, dcContact.getAddr());
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class BlockClickedListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (contactToEditRecipient.isBlocked()) handleUnblock();
|
||||
else handleBlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleBlock() {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(R.string.ask_block_contact)
|
||||
.setCancelable(true)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.menu_block_contact, (dialog, which) -> {
|
||||
setBlocked(true);
|
||||
contactToEditRecipient.reload(getActivity());
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void handleUnblock() {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(R.string.ask_unblock_contact)
|
||||
.setCancelable(true)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.menu_unblock_contact, (dialog, which) -> {
|
||||
setBlocked(false);
|
||||
contactToEditRecipient.reload(getActivity());
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void setBlocked(final boolean blocked) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
dcContext.blockContact(contactToEditRecipient.getAddress().getDcContactId(), blocked ? 1 : 0);
|
||||
return null;
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user