cleanup, move several options to the more visible menu

This commit is contained in:
B. Petersen 2019-05-23 18:38:53 +02:00
parent a17cfccba4
commit f59687d6af
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
6 changed files with 247 additions and 135 deletions

22
res/menu/profile_chat.xml Normal file
View file

@ -0,0 +1,22 @@
<?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:title="@string/menu_group_name_and_image"
android:id="@+id/edit_group_name_and_image"
android:icon="@drawable/ic_create_white_24dp"
app:showAsAction="always"/>
<item android:title="@string/menu_mute"
android:id="@+id/menu_mute_notifications"
app:showAsAction="never"/>
<item android:title="@string/pref_sound"
android:id="@+id/menu_sound"
app:showAsAction="never"/>
<item android:title="@string/pref_vibrate"
android:id="@+id/menu_vibrate"
app:showAsAction="never"/>
</menu>

View file

@ -0,0 +1,18 @@
<?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:title="@string/menu_edit_name"
android:id="@+id/edit_contact_name"
android:icon="@drawable/ic_create_white_24dp"
app:showAsAction="always"/>
<item android:title="@string/profile_encryption"
android:id="@+id/show_encr_info"
app:showAsAction="never"/>
<item android:title="@string/menu_block_contact"
android:id="@+id/block_contact"
app:showAsAction="never"/>
</menu>

View file

@ -251,6 +251,7 @@
<string name="profile_shared_chats">Shared chats</string> <string name="profile_shared_chats">Shared chats</string>
<string name="tab_contact">Contact</string> <string name="tab_contact">Contact</string>
<string name="tab_group">Group</string> <string name="tab_group">Group</string>
<string name="tab_members">Members</string>
<string name="tab_gallery">Gallery</string> <string name="tab_gallery">Gallery</string>
<string name="tab_docs">Docs</string> <string name="tab_docs">Docs</string>
<string name="tab_links">Links</string> <string name="tab_links">Links</string>

View file

@ -1,13 +1,22 @@
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.app.Activity;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.EditText;
import com.b44t.messenger.DcChat; import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcContact; import com.b44t.messenger.DcContact;
@ -19,9 +28,11 @@ import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme; import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.ViewUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class ProfileActivity extends PassphraseRequiredActionBarActivity public class ProfileActivity extends PassphraseRequiredActionBarActivity
implements DcEventCenter.DcEventDelegate implements DcEventCenter.DcEventDelegate
@ -40,6 +51,8 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
public static final int TAB_LINKS = 40; public static final int TAB_LINKS = 40;
public static final int TAB_MAP = 50; public static final int TAB_MAP = 50;
private static final int REQUEST_CODE_PICK_RINGTONE = 1;
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme(); private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
@ -73,6 +86,25 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this); dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this);
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if (chatId!=0) {
inflater.inflate(R.menu.profile_chat, menu);
if(!chatIsGroup) {
menu.findItem(R.id.edit_group_name_and_image).setVisible(false);
}
}
if (isContactProfile()) {
inflater.inflate(R.menu.profile_contact, menu);
}
super.onCreateOptionsMenu(menu);
return true;
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
@ -86,17 +118,6 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
super.onDestroy(); super.onDestroy();
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case android.R.id.home: finish(); return true;
}
return false;
}
@Override @Override
public void handleEvent(int eventId, Object data1, Object data2) { public void handleEvent(int eventId, Object data1, Object data2) {
updateToolbar(); updateToolbar();
@ -217,7 +238,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
return getString(contactId==DcContact.DC_CONTACT_ID_SELF? R.string.self : R.string.tab_contact); return getString(contactId==DcContact.DC_CONTACT_ID_SELF? R.string.self : R.string.tab_contact);
} }
else { else {
return getString(R.string.tab_group); return getString(R.string.tab_members);
} }
case TAB_GALLERY: case TAB_GALLERY:
@ -237,4 +258,152 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
} }
} }
} }
// handle events
// =========================================================================
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.menu_mute_notifications:
onNotifyOnOff();
break;
case R.id.menu_sound:
onSoundSettings();
break;
case R.id.menu_vibrate:
onVibrateSettings();
break;
case R.id.edit_group_name_and_image:
onEditGroupNameAndImage();
break;
case R.id.edit_contact_name:
onEditContactName();
break;
case R.id.show_encr_info:
onEncrInfo();
break;
case R.id.block_contact:
onBlockContact();
break;
}
return false;
}
public void onNotifyOnOff() {
if (Prefs.isChatMuted(this, chatId)) {
setMuted(0);
}
else {
MuteDialog.show(this, until -> setMuted(until));
}
}
private void setMuted(final long until) {
if(chatId!=0) {
Prefs.setChatMutedUntil(this, chatId, until);
}
}
public void onSoundSettings() {
Uri current = dcContext.getRecipient(dcContext.getChat(chatId)).getMessageRingtone();
Uri defaultUri = Prefs.getNotificationRingtone(this);
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);
}
public void onVibrateSettings() {
new AlertDialog.Builder(this)
.setTitle(R.string.pref_vibrate)
.setItems(R.array.recipient_vibrate_entries, (dialog, which) -> {
Prefs.setChatVibrate(this, chatId, Prefs.VibrateState.fromId(which));
})
.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);
}
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 onEncrInfo() {
String info_str = dcContext.getContactEncrInfo(contactId);
new AlertDialog.Builder(this)
.setMessage(info_str)
.setPositiveButton(android.R.string.ok, null)
.show();
}
public void onBlockContact() {
DcContact dcContact = dcContext.getContact(contactId);
if(dcContact.isBlocked()) {
new AlertDialog.Builder(this)
.setMessage(R.string.ask_unblock_contact)
.setCancelable(true)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.menu_unblock_contact, (dialog, which) -> {
dcContext.blockContact(contactId, 0);
}).show();
}
else {
new AlertDialog.Builder(this)
.setMessage(R.string.ask_block_contact)
.setCancelable(true)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.menu_block_contact, (dialog, which) -> {
dcContext.blockContact(contactId, 1);
}).show();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==REQUEST_CODE_PICK_RINGTONE && resultCode== Activity.RESULT_OK && data!=null) {
Uri value = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
Uri defaultValue = Prefs.getNotificationRingtone(this);
if (defaultValue.equals(value)) value = null;
else if (value == null) value = Uri.EMPTY;
Prefs.setChatRingtone(this, chatId, value);
}
}
} }

View file

@ -269,13 +269,13 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
for (int i = 0; i < memberList.length; i++) { for (int i = 0; i < memberList.length; i++) {
itemData.add(new ItemData(ItemData.TYPE_MEMBER, memberList[i], 0)); itemData.add(new ItemData(ItemData.TYPE_MEMBER, memberList[i], 0));
} }
itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_GROUP_NAME_N_IMAGE, context.getString(R.string.menu_group_name_and_image))); // itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_GROUP_NAME_N_IMAGE, context.getString(R.string.menu_group_name_and_image)));
} }
else if (sharedChats!=null && dcContact!=null) { else if (sharedChats!=null && dcContact!=null) {
itemDataContact = dcContact; itemDataContact = dcContact;
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_ADDR,dcContact.getAddr())); itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_ADDR,dcContact.getAddr()));
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_NAME, context.getString(R.string.menu_edit_name))); // itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_NAME, context.getString(R.string.menu_edit_name)));
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_ENCRYPTION, context.getString(R.string.profile_encryption))); // itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_ENCRYPTION, context.getString(R.string.profile_encryption)));
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_NEW_CHAT, context.getString(R.string.menu_new_chat))); itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_NEW_CHAT, context.getString(R.string.menu_new_chat)));
itemDataSharedChats = sharedChats; itemDataSharedChats = sharedChats;
int sharedChatsCnt = sharedChats.getCnt(); int sharedChatsCnt = sharedChats.getCnt();
@ -284,17 +284,17 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
} }
} }
if(dcChat!=null) { // if(dcChat!=null) {
itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_NOTIFY, // itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_NOTIFY,
context.getString(Prefs.isChatMuted(context, dcChat.getId())? R.string.menu_unmute : R.string.menu_mute))); // context.getString(Prefs.isChatMuted(context, dcChat.getId())? R.string.menu_unmute : R.string.menu_mute)));
itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_SOUND, context.getString(R.string.pref_sound))); // itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_SOUND, context.getString(R.string.pref_sound)));
itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_VIBRATE, context.getString(R.string.pref_vibrate))); // itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_VIBRATE, context.getString(R.string.pref_vibrate)));
} // }
if (dcContact!=null) { // if (dcContact!=null) {
itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_BLOCK_CONTACT, // itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_BLOCK_CONTACT,
context.getString(dcContact.isBlocked()? R.string.menu_unblock_contact : R.string.menu_block_contact))); // context.getString(dcContact.isBlocked()? R.string.menu_unblock_contact : R.string.menu_block_contact)));
} // }
notifyDataSetChanged(); notifyDataSetChanged();
} }

View file

@ -6,7 +6,6 @@ import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
@ -49,7 +48,6 @@ public class ProfileSettingsFragment extends Fragment
public static final String CHAT_ID_EXTRA = "chat_id"; public static final String CHAT_ID_EXTRA = "chat_id";
public static final String CONTACT_ID_EXTRA = "contact_id"; public static final String CONTACT_ID_EXTRA = "contact_id";
private static final int REQUEST_CODE_PICK_RINGTONE = 1;
private static final int REQUEST_CODE_PICK_CONTACT = 2; private static final int REQUEST_CODE_PICK_CONTACT = 2;
private RecyclerView list; private RecyclerView list;
@ -128,7 +126,7 @@ public class ProfileSettingsFragment extends Fragment
} }
// handle the various events // handle events
// ========================================================================= // =========================================================================
@Override @Override
@ -137,26 +135,26 @@ public class ProfileSettingsFragment extends Fragment
case ProfileSettingsAdapter.SETTING_CONTACT_ADDR: case ProfileSettingsAdapter.SETTING_CONTACT_ADDR:
onContactAddrClicked(); onContactAddrClicked();
break; break;
case ProfileSettingsAdapter.SETTING_CONTACT_NAME:
onEditContactName();
break;
case ProfileSettingsAdapter.SETTING_ENCRYPTION:
onEncrInfo();
break;
case ProfileSettingsAdapter.SETTING_NEW_CHAT: case ProfileSettingsAdapter.SETTING_NEW_CHAT:
onNewChat(); onNewChat();
break; break;
case ProfileSettingsAdapter.SETTING_CONTACT_NAME:
((ProfileActivity)getActivity()).onEditContactName();
break;
case ProfileSettingsAdapter.SETTING_ENCRYPTION:
((ProfileActivity)getActivity()).onEncrInfo();
break;
case ProfileSettingsAdapter.SETTING_BLOCK_CONTACT: case ProfileSettingsAdapter.SETTING_BLOCK_CONTACT:
onBlockContact(); ((ProfileActivity)getActivity()).onBlockContact();
break; break;
case ProfileSettingsAdapter.SETTING_NOTIFY: case ProfileSettingsAdapter.SETTING_NOTIFY:
onNotifyOnOff(); ((ProfileActivity)getActivity()).onNotifyOnOff();
break; break;
case ProfileSettingsAdapter.SETTING_SOUND: case ProfileSettingsAdapter.SETTING_SOUND:
onSoundSettings(); ((ProfileActivity)getActivity()).onSoundSettings();
break; break;
case ProfileSettingsAdapter.SETTING_VIBRATE: case ProfileSettingsAdapter.SETTING_VIBRATE:
onVibrateSettings(); ((ProfileActivity)getActivity()).onVibrateSettings();
break; break;
} }
} }
@ -251,29 +249,6 @@ public class ProfileSettingsFragment extends Fragment
.show(); .show();
} }
private void onEncrInfo() {
String info_str = dcContext.getContactEncrInfo(contactId);
new AlertDialog.Builder(getActivity())
.setMessage(info_str)
.setPositiveButton(android.R.string.ok, null)
.show();
}
private void onEditContactName() {
DcContact dcContact = dcContext.getContact(contactId);
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();
}
private void onNewChat() { private void onNewChat() {
DcContact dcContact = dcContext.getContact(contactId); DcContact dcContact = dcContext.getContact(contactId);
new AlertDialog.Builder(getActivity()) new AlertDialog.Builder(getActivity())
@ -291,70 +266,6 @@ public class ProfileSettingsFragment extends Fragment
.show(); .show();
} }
private void onBlockContact() {
DcContact dcContact = dcContext.getContact(contactId);
if(dcContact.isBlocked()) {
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) -> {
dcContext.blockContact(contactId, 0);
}).show();
}
else {
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) -> {
dcContext.blockContact(contactId, 1);
}).show();
}
}
private void onNotifyOnOff() {
if (Prefs.isChatMuted(getContext(), chatId)) {
setMuted(0);
}
else {
MuteDialog.show(getActivity(), until -> setMuted(until));
}
}
private void setMuted(final long until) {
if(chatId!=0) {
Prefs.setChatMutedUntil(getActivity(), chatId, until);
update(); // in contrast to most other settings, muting is handled in the ui and does not result in an DC_EVENT
}
}
private void onSoundSettings() {
Uri current = dcContext.getRecipient(dcContext.getChat(chatId)).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);
}
private void onVibrateSettings() {
new AlertDialog.Builder(getContext())
.setTitle(R.string.pref_vibrate)
.setItems(R.array.recipient_vibrate_entries, (dialog, which) -> {
Prefs.setChatVibrate(getContext(), chatId, Prefs.VibrateState.fromId(which));
})
.show();
}
private class ActionModeCallback implements ActionMode.Callback { private class ActionModeCallback implements ActionMode.Callback {
private int originalStatusBarColor; private int originalStatusBarColor;
@ -417,16 +328,7 @@ public class ProfileSettingsFragment extends Fragment
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode==REQUEST_CODE_PICK_RINGTONE && resultCode==Activity.RESULT_OK && data!=null) { if (requestCode==REQUEST_CODE_PICK_CONTACT && resultCode==Activity.RESULT_OK && data!=null) {
Uri value = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
Uri defaultValue = Prefs.getNotificationRingtone(getContext());
if (defaultValue.equals(value)) value = null;
else if (value == null) value = Uri.EMPTY;
Prefs.setChatRingtone(getContext(), chatId, value);
}
else if (requestCode==REQUEST_CODE_PICK_CONTACT && resultCode==Activity.RESULT_OK && data!=null) {
List<String> selected = data.getStringArrayListExtra("contacts"); List<String> selected = data.getStringArrayListExtra("contacts");
for (String addr : selected) { for (String addr : selected) {
if (addr!=null) { if (addr!=null) {