2014-11-17 03:44:57 +01:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2014-11-17 03:44:57 +01:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2017-03-31 01:58:05 +02:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
2014-11-17 03:44:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2014-11-17 23:04:31 +01:00
|
|
|
import android.app.Activity;
|
2014-11-17 03:44:57 +01:00
|
|
|
import android.content.Context;
|
2014-11-17 23:04:31 +01:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.SharedPreferences;
|
2014-11-17 03:44:57 +01:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.ContactsController;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
import org.telegram.messenger.R;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.support.widget.LinearLayoutManager;
|
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.RequestDelegate;
|
|
|
|
import org.telegram.tgnet.TLObject;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.ui.Cells.HeaderCell;
|
2016-03-06 02:49:31 +01:00
|
|
|
import org.telegram.ui.Cells.RadioCell;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.ui.Cells.TextInfoPrivacyCell;
|
|
|
|
import org.telegram.ui.Cells.TextSettingsCell;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2014-11-17 03:44:57 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public class PrivacyControlActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
2014-11-17 03:44:57 +01:00
|
|
|
|
|
|
|
private ListAdapter listAdapter;
|
|
|
|
private View doneButton;
|
2017-03-31 01:58:05 +02:00
|
|
|
private RecyclerListView listView;
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private int rulesType;
|
2014-11-17 03:44:57 +01:00
|
|
|
private ArrayList<Integer> currentPlus;
|
|
|
|
private ArrayList<Integer> currentMinus;
|
2015-10-29 18:10:07 +01:00
|
|
|
private int lastCheckedType = -1;
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private int currentType;
|
2016-03-06 02:49:31 +01:00
|
|
|
|
|
|
|
private boolean enableAnimation;
|
|
|
|
|
|
|
|
private int sectionRow;
|
2014-11-17 03:44:57 +01:00
|
|
|
private int everybodyRow;
|
|
|
|
private int myContactsRow;
|
|
|
|
private int nobodyRow;
|
2016-03-06 02:49:31 +01:00
|
|
|
private int detailRow;
|
2014-11-17 03:44:57 +01:00
|
|
|
private int shareSectionRow;
|
|
|
|
private int alwaysShareRow;
|
|
|
|
private int neverShareRow;
|
|
|
|
private int shareDetailRow;
|
|
|
|
private int rowCount;
|
|
|
|
|
|
|
|
private final static int done_button = 1;
|
|
|
|
|
|
|
|
private static class LinkMovementMethodMy extends LinkMovementMethod {
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
|
|
|
|
try {
|
|
|
|
return super.onTouchEvent(widget, buffer, event);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public PrivacyControlActivity(int type) {
|
2016-03-06 02:49:31 +01:00
|
|
|
super();
|
2017-03-31 01:58:05 +02:00
|
|
|
rulesType = type;
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
|
|
|
checkPrivacy();
|
|
|
|
updateRows();
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.privacyRulesUpdated);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.privacyRulesUpdated);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setAllowOverlayTitle(true);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (rulesType == 2) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("Calls", R.string.Calls));
|
|
|
|
} else if (rulesType == 1) {
|
2016-03-06 02:49:31 +01:00
|
|
|
actionBar.setTitle(LocaleController.getString("GroupsAndChannels", R.string.GroupsAndChannels));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("PrivacyLastSeen", R.string.PrivacyLastSeen));
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
|
|
|
} else if (id == done_button) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-17 23:04:31 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
if (currentType != 0 && rulesType == 0) {
|
2015-04-09 20:00:14 +02:00
|
|
|
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
boolean showed = preferences.getBoolean("privacyAlertShowed", false);
|
|
|
|
if (!showed) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2017-03-31 01:58:05 +02:00
|
|
|
if (rulesType == 1) {
|
2016-03-06 02:49:31 +01:00
|
|
|
builder.setMessage(LocaleController.getString("WhoCanAddMeInfo", R.string.WhoCanAddMeInfo));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("CustomHelp", R.string.CustomHelp));
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
applyCurrentPrivacySettings();
|
|
|
|
preferences.edit().putBoolean("privacyAlertShowed", true).commit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2015-04-09 20:00:14 +02:00
|
|
|
return;
|
2014-11-17 23:04:31 +01:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
applyCurrentPrivacySettings();
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
|
|
|
|
doneButton.setVisibility(View.GONE);
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
listAdapter = new ListAdapter(context);
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
fragmentView = new FrameLayout(context);
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
2017-03-31 01:58:05 +02:00
|
|
|
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
listView = new RecyclerListView(context);
|
|
|
|
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
2017-03-31 01:58:05 +02:00
|
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setAdapter(listAdapter);
|
2017-03-31 01:58:05 +02:00
|
|
|
listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public void onItemClick(View view, final int position) {
|
|
|
|
if (position == nobodyRow || position == everybodyRow || position == myContactsRow) {
|
2015-04-09 20:00:14 +02:00
|
|
|
int newType = currentType;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (position == nobodyRow) {
|
2015-04-09 20:00:14 +02:00
|
|
|
newType = 1;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (position == everybodyRow) {
|
2015-04-09 20:00:14 +02:00
|
|
|
newType = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (position == myContactsRow) {
|
2015-04-09 20:00:14 +02:00
|
|
|
newType = 2;
|
|
|
|
}
|
|
|
|
if (newType == currentType) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
enableAnimation = true;
|
2015-04-09 20:00:14 +02:00
|
|
|
doneButton.setVisibility(View.VISIBLE);
|
2015-10-29 18:10:07 +01:00
|
|
|
lastCheckedType = currentType;
|
2015-04-09 20:00:14 +02:00
|
|
|
currentType = newType;
|
|
|
|
updateRows();
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (position == neverShareRow || position == alwaysShareRow) {
|
2015-05-21 23:27:27 +02:00
|
|
|
ArrayList<Integer> createFromArray;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (position == neverShareRow) {
|
2015-04-09 20:00:14 +02:00
|
|
|
createFromArray = currentMinus;
|
|
|
|
} else {
|
|
|
|
createFromArray = currentPlus;
|
|
|
|
}
|
|
|
|
if (createFromArray.isEmpty()) {
|
|
|
|
Bundle args = new Bundle();
|
2017-03-31 01:58:05 +02:00
|
|
|
args.putBoolean(position == neverShareRow ? "isNeverShare" : "isAlwaysShare", true);
|
|
|
|
args.putBoolean("isGroup", rulesType != 0);
|
2015-04-09 20:00:14 +02:00
|
|
|
GroupCreateActivity fragment = new GroupCreateActivity(args);
|
|
|
|
fragment.setDelegate(new GroupCreateActivity.GroupCreateActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectUsers(ArrayList<Integer> ids) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (position == neverShareRow) {
|
2015-04-09 20:00:14 +02:00
|
|
|
currentMinus = ids;
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < currentMinus.size(); a++) {
|
|
|
|
currentPlus.remove(currentMinus.get(a));
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentPlus = ids;
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < currentPlus.size(); a++) {
|
|
|
|
currentMinus.remove(currentPlus.get(a));
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
doneButton.setVisibility(View.VISIBLE);
|
2015-10-29 18:10:07 +01:00
|
|
|
lastCheckedType = -1;
|
2015-04-09 20:00:14 +02:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
PrivacyUsersActivity fragment = new PrivacyUsersActivity(createFromArray, rulesType != 0, position == alwaysShareRow);
|
2016-03-06 02:49:31 +01:00
|
|
|
fragment.setDelegate(new PrivacyUsersActivity.PrivacyActivityDelegate() {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void didUpdatedUserList(ArrayList<Integer> ids, boolean added) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (position == neverShareRow) {
|
2015-04-09 20:00:14 +02:00
|
|
|
currentMinus = ids;
|
|
|
|
if (added) {
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < currentMinus.size(); a++) {
|
|
|
|
currentPlus.remove(currentMinus.get(a));
|
2014-11-21 20:36:21 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentPlus = ids;
|
|
|
|
if (added) {
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < currentPlus.size(); a++) {
|
|
|
|
currentMinus.remove(currentPlus.get(a));
|
2014-11-21 20:36:21 +01:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
doneButton.setVisibility(View.VISIBLE);
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
|
|
|
if (id == NotificationCenter.privacyRulesUpdated) {
|
|
|
|
checkPrivacy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-17 23:04:31 +01:00
|
|
|
private void applyCurrentPrivacySettings() {
|
|
|
|
TLRPC.TL_account_setPrivacy req = new TLRPC.TL_account_setPrivacy();
|
2017-03-31 01:58:05 +02:00
|
|
|
if (rulesType == 2) {
|
|
|
|
req.key = new TLRPC.TL_inputPrivacyKeyPhoneCall();
|
|
|
|
} else if (rulesType == 1) {
|
2016-03-06 02:49:31 +01:00
|
|
|
req.key = new TLRPC.TL_inputPrivacyKeyChatInvite();
|
|
|
|
} else {
|
|
|
|
req.key = new TLRPC.TL_inputPrivacyKeyStatusTimestamp();
|
|
|
|
}
|
2014-11-17 23:04:31 +01:00
|
|
|
if (currentType != 0 && currentPlus.size() > 0) {
|
|
|
|
TLRPC.TL_inputPrivacyValueAllowUsers rule = new TLRPC.TL_inputPrivacyValueAllowUsers();
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < currentPlus.size(); a++) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentPlus.get(a));
|
2014-11-17 23:04:31 +01:00
|
|
|
if (user != null) {
|
|
|
|
TLRPC.InputUser inputUser = MessagesController.getInputUser(user);
|
|
|
|
if (inputUser != null) {
|
|
|
|
rule.users.add(inputUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req.rules.add(rule);
|
|
|
|
}
|
|
|
|
if (currentType != 1 && currentMinus.size() > 0) {
|
|
|
|
TLRPC.TL_inputPrivacyValueDisallowUsers rule = new TLRPC.TL_inputPrivacyValueDisallowUsers();
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < currentMinus.size(); a++) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentMinus.get(a));
|
2014-11-17 23:04:31 +01:00
|
|
|
if (user != null) {
|
|
|
|
TLRPC.InputUser inputUser = MessagesController.getInputUser(user);
|
|
|
|
if (inputUser != null) {
|
|
|
|
rule.users.add(inputUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req.rules.add(rule);
|
|
|
|
}
|
|
|
|
if (currentType == 0) {
|
|
|
|
req.rules.add(new TLRPC.TL_inputPrivacyValueAllowAll());
|
|
|
|
} else if (currentType == 1) {
|
|
|
|
req.rules.add(new TLRPC.TL_inputPrivacyValueDisallowAll());
|
|
|
|
} else if (currentType == 2) {
|
|
|
|
req.rules.add(new TLRPC.TL_inputPrivacyValueAllowContacts());
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
AlertDialog progressDialog = null;
|
2016-01-11 18:19:48 +01:00
|
|
|
if (getParentActivity() != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
progressDialog = new AlertDialog(getParentActivity(), 1);
|
2016-01-11 18:19:48 +01:00
|
|
|
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
|
|
|
|
progressDialog.setCanceledOnTouchOutside(false);
|
|
|
|
progressDialog.setCancelable(false);
|
|
|
|
progressDialog.show();
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
final AlertDialog progressDialogFinal = progressDialog;
|
2015-09-24 22:52:02 +02:00
|
|
|
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
|
2014-11-17 23:04:31 +01:00
|
|
|
@Override
|
|
|
|
public void run(final TLObject response, final TLRPC.TL_error error) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (progressDialogFinal != null) {
|
|
|
|
progressDialogFinal.dismiss();
|
|
|
|
}
|
2014-11-17 23:04:31 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-11-17 23:04:31 +01:00
|
|
|
}
|
|
|
|
if (error == null) {
|
|
|
|
finishFragment();
|
|
|
|
TLRPC.TL_account_privacyRules rules = (TLRPC.TL_account_privacyRules) response;
|
|
|
|
MessagesController.getInstance().putUsers(rules.users, false);
|
2017-03-31 01:58:05 +02:00
|
|
|
ContactsController.getInstance().setPrivacyRules(rules.rules, rulesType);
|
2014-11-17 23:04:31 +01:00
|
|
|
} else {
|
|
|
|
showErrorAlert();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
}, ConnectionsManager.RequestFlagFailOnServerErrors);
|
2014-11-17 23:04:31 +01:00
|
|
|
}
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
private void showErrorAlert() {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("PrivacyFloodControlError", R.string.PrivacyFloodControlError));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
showDialog(builder.create());
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void checkPrivacy() {
|
2015-01-02 23:15:07 +01:00
|
|
|
currentPlus = new ArrayList<>();
|
|
|
|
currentMinus = new ArrayList<>();
|
2017-03-31 01:58:05 +02:00
|
|
|
ArrayList<TLRPC.PrivacyRule> privacyRules = ContactsController.getInstance().getPrivacyRules(rulesType);
|
|
|
|
if (privacyRules == null || privacyRules.size() == 0) {
|
2014-11-17 03:44:57 +01:00
|
|
|
currentType = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int type = -1;
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < privacyRules.size(); a++) {
|
|
|
|
TLRPC.PrivacyRule rule = privacyRules.get(a);
|
2014-11-17 03:44:57 +01:00
|
|
|
if (rule instanceof TLRPC.TL_privacyValueAllowUsers) {
|
|
|
|
currentPlus.addAll(rule.users);
|
|
|
|
} else if (rule instanceof TLRPC.TL_privacyValueDisallowUsers) {
|
|
|
|
currentMinus.addAll(rule.users);
|
|
|
|
} else if (rule instanceof TLRPC.TL_privacyValueAllowAll) {
|
|
|
|
type = 0;
|
|
|
|
} else if (rule instanceof TLRPC.TL_privacyValueDisallowAll) {
|
|
|
|
type = 1;
|
|
|
|
} else {
|
|
|
|
type = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == 0 || type == -1 && currentMinus.size() > 0) {
|
|
|
|
currentType = 0;
|
|
|
|
} else if (type == 2 || type == -1 && currentMinus.size() > 0 && currentPlus.size() > 0) {
|
|
|
|
currentType = 2;
|
|
|
|
} else if (type == 1 || type == -1 && currentPlus.size() > 0) {
|
|
|
|
currentType = 1;
|
|
|
|
}
|
|
|
|
if (doneButton != null) {
|
|
|
|
doneButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
updateRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateRows() {
|
|
|
|
rowCount = 0;
|
2016-03-06 02:49:31 +01:00
|
|
|
sectionRow = rowCount++;
|
2014-11-17 03:44:57 +01:00
|
|
|
everybodyRow = rowCount++;
|
|
|
|
myContactsRow = rowCount++;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (rulesType != 0 && rulesType != 2) {
|
2016-03-06 02:49:31 +01:00
|
|
|
nobodyRow = -1;
|
|
|
|
} else {
|
|
|
|
nobodyRow = rowCount++;
|
|
|
|
}
|
|
|
|
detailRow = rowCount++;
|
2014-11-17 03:44:57 +01:00
|
|
|
shareSectionRow = rowCount++;
|
|
|
|
if (currentType == 1 || currentType == 2) {
|
|
|
|
alwaysShareRow = rowCount++;
|
|
|
|
} else {
|
|
|
|
alwaysShareRow = -1;
|
|
|
|
}
|
|
|
|
if (currentType == 0 || currentType == 2) {
|
|
|
|
neverShareRow = rowCount++;
|
|
|
|
} else {
|
|
|
|
neverShareRow = -1;
|
|
|
|
}
|
|
|
|
shareDetailRow = rowCount++;
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2015-10-29 18:10:07 +01:00
|
|
|
lastCheckedType = -1;
|
2016-03-06 02:49:31 +01:00
|
|
|
enableAnimation = false;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
2014-11-17 03:44:57 +01:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
int position = holder.getAdapterPosition();
|
|
|
|
return position == nobodyRow || position == everybodyRow || position == myContactsRow || position == neverShareRow || position == alwaysShareRow;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public int getItemCount() {
|
2014-11-17 03:44:57 +01:00
|
|
|
return rowCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
|
|
|
view = new TextSettingsCell(mContext);
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
view = new TextInfoPrivacyCell(mContext);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
view = new HeaderCell(mContext);
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
view = new RadioCell(mContext);
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return new RecyclerListView.Holder(view);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
case 0:
|
|
|
|
TextSettingsCell textCell = (TextSettingsCell) holder.itemView;
|
|
|
|
if (position == alwaysShareRow) {
|
|
|
|
String value;
|
|
|
|
if (currentPlus.size() != 0) {
|
|
|
|
value = LocaleController.formatPluralString("Users", currentPlus.size());
|
|
|
|
} else {
|
|
|
|
value = LocaleController.getString("EmpryUsersPlaceholder", R.string.EmpryUsersPlaceholder);
|
|
|
|
}
|
|
|
|
if (rulesType != 0) {
|
|
|
|
textCell.setTextAndValue(LocaleController.getString("AlwaysAllow", R.string.AlwaysAllow), value, neverShareRow != -1);
|
|
|
|
} else {
|
|
|
|
textCell.setTextAndValue(LocaleController.getString("AlwaysShareWith", R.string.AlwaysShareWith), value, neverShareRow != -1);
|
|
|
|
}
|
|
|
|
} else if (position == neverShareRow) {
|
|
|
|
String value;
|
|
|
|
if (currentMinus.size() != 0) {
|
|
|
|
value = LocaleController.formatPluralString("Users", currentMinus.size());
|
|
|
|
} else {
|
|
|
|
value = LocaleController.getString("EmpryUsersPlaceholder", R.string.EmpryUsersPlaceholder);
|
|
|
|
}
|
|
|
|
if (rulesType != 0) {
|
|
|
|
textCell.setTextAndValue(LocaleController.getString("NeverAllow", R.string.NeverAllow), value, false);
|
|
|
|
} else {
|
|
|
|
textCell.setTextAndValue(LocaleController.getString("NeverShareWith", R.string.NeverShareWith), value, false);
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
TextInfoPrivacyCell privacyCell = (TextInfoPrivacyCell) holder.itemView;
|
|
|
|
if (position == detailRow) {
|
|
|
|
if (rulesType == 2) {
|
|
|
|
privacyCell.setText(LocaleController.getString("WhoCanCallMeInfo", R.string.WhoCanCallMeInfo));
|
|
|
|
} else if (rulesType == 1) {
|
|
|
|
privacyCell.setText(LocaleController.getString("WhoCanAddMeInfo", R.string.WhoCanAddMeInfo));
|
|
|
|
} else {
|
|
|
|
privacyCell.setText(LocaleController.getString("CustomHelp", R.string.CustomHelp));
|
|
|
|
}
|
|
|
|
privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
} else if (position == shareDetailRow) {
|
|
|
|
if (rulesType == 2) {
|
|
|
|
privacyCell.setText(LocaleController.getString("CustomCallInfo", R.string.CustomCallInfo));
|
|
|
|
} else if (rulesType == 1) {
|
|
|
|
privacyCell.setText(LocaleController.getString("CustomShareInfo", R.string.CustomShareInfo));
|
|
|
|
} else {
|
|
|
|
privacyCell.setText(LocaleController.getString("CustomShareSettingsHelp", R.string.CustomShareSettingsHelp));
|
|
|
|
}
|
|
|
|
privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
HeaderCell headerCell = (HeaderCell) holder.itemView;
|
|
|
|
if (position == sectionRow) {
|
|
|
|
if (rulesType == 2) {
|
|
|
|
headerCell.setText(LocaleController.getString("WhoCanCallMe", R.string.WhoCanCallMe));
|
|
|
|
} else if (rulesType == 1) {
|
|
|
|
headerCell.setText(LocaleController.getString("WhoCanAddMe", R.string.WhoCanAddMe));
|
|
|
|
} else {
|
|
|
|
headerCell.setText(LocaleController.getString("LastSeenTitle", R.string.LastSeenTitle));
|
|
|
|
}
|
|
|
|
} else if (position == shareSectionRow) {
|
|
|
|
headerCell.setText(LocaleController.getString("AddExceptions", R.string.AddExceptions));
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
RadioCell radioCell = (RadioCell) holder.itemView;
|
|
|
|
int checkedType = 0;
|
|
|
|
if (position == everybodyRow) {
|
|
|
|
radioCell.setText(LocaleController.getString("LastSeenEverybody", R.string.LastSeenEverybody), lastCheckedType == 0, true);
|
|
|
|
checkedType = 0;
|
|
|
|
} else if (position == myContactsRow) {
|
|
|
|
radioCell.setText(LocaleController.getString("LastSeenContacts", R.string.LastSeenContacts), lastCheckedType == 2, nobodyRow != -1);
|
|
|
|
checkedType = 2;
|
|
|
|
} else if (position == nobodyRow) {
|
|
|
|
radioCell.setText(LocaleController.getString("LastSeenNobody", R.string.LastSeenNobody), lastCheckedType == 1, false);
|
|
|
|
checkedType = 1;
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (lastCheckedType == checkedType) {
|
|
|
|
radioCell.setChecked(false, enableAnimation);
|
|
|
|
} else if (currentType == checkedType) {
|
|
|
|
radioCell.setChecked(true, enableAnimation);
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public int getItemViewType(int position) {
|
|
|
|
if (position == alwaysShareRow || position == neverShareRow) {
|
2014-11-17 03:44:57 +01:00
|
|
|
return 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (position == shareDetailRow || position == detailRow) {
|
2014-11-17 03:44:57 +01:00
|
|
|
return 1;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (position == sectionRow || position == shareSectionRow) {
|
2014-11-17 03:44:57 +01:00
|
|
|
return 2;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (position == everybodyRow || position == myContactsRow || position == nobodyRow) {
|
2015-10-29 18:10:07 +01:00
|
|
|
return 3;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public ThemeDescription[] getThemeDescriptions() {
|
|
|
|
return new ThemeDescription[]{
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{TextSettingsCell.class, HeaderCell.class, RadioCell.class}, null, null, null, Theme.key_windowBackgroundWhite),
|
|
|
|
new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray),
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{TextInfoPrivacyCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{TextInfoPrivacyCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText4),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{RadioCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOX, new Class[]{RadioCell.class}, new String[]{"radioButton"}, null, null, null, Theme.key_radioBackground),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOXCHECK, new Class[]{RadioCell.class}, new String[]{"radioButton"}, null, null, null, Theme.key_radioBackgroundChecked),
|
|
|
|
};
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|