2013-10-25 15:19:00 +00:00
|
|
|
/*
|
2013-12-20 19:25:49 +00:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 15:19:00 +00: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).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.media.Ringtone;
|
|
|
|
import android.media.RingtoneManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.provider.Settings;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
import android.support.v7.app.ActionBarActivity;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.LayoutInflater;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.view.MenuItem;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.messenger.TLObject;
|
|
|
|
import org.telegram.messenger.TLRPC;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2013-12-20 19:25:49 +00:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-02-04 18:36:55 +00:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.RPCRequest;
|
|
|
|
import org.telegram.messenger.Utilities;
|
|
|
|
import org.telegram.ui.Views.BaseFragment;
|
|
|
|
import org.telegram.ui.Views.OnSwipeTouchListener;
|
|
|
|
|
|
|
|
public class SettingsNotificationsActivity extends BaseFragment {
|
|
|
|
private ListView listView;
|
|
|
|
private boolean reseting = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
if (fragmentView == null) {
|
|
|
|
fragmentView = inflater.inflate(R.layout.settings_layout, container, false);
|
|
|
|
ListAdapter listAdapter = new ListAdapter(parentActivity);
|
|
|
|
listView = (ListView)fragmentView.findViewById(R.id.listView);
|
|
|
|
listView.setAdapter(listAdapter);
|
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
|
if (i == 1 || i == 6) {
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
2013-12-20 19:25:49 +00:00
|
|
|
boolean enabled;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (i == 1) {
|
|
|
|
enabled = preferences.getBoolean("EnableAll", true);
|
|
|
|
editor.putBoolean("EnableAll", !enabled);
|
|
|
|
} else if (i == 6) {
|
|
|
|
enabled = preferences.getBoolean("EnableGroup", true);
|
|
|
|
editor.putBoolean("EnableGroup", !enabled);
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
|
|
|
} else if (i == 2 || i == 7) {
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
boolean enabledAll = true;
|
2013-12-20 19:25:49 +00:00
|
|
|
boolean enabled;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (i == 2) {
|
|
|
|
enabled = preferences.getBoolean("EnablePreviewAll", true);
|
|
|
|
editor.putBoolean("EnablePreviewAll", !enabled);
|
|
|
|
} else if (i == 7) {
|
|
|
|
enabled = preferences.getBoolean("EnablePreviewGroup", true);
|
|
|
|
editor.putBoolean("EnablePreviewGroup", !enabled);
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
|
|
|
} else if (i == 3 || i == 8) {
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
boolean enabled;
|
|
|
|
if (i == 3) {
|
|
|
|
enabled = preferences.getBoolean("EnableVibrateAll", true);
|
|
|
|
editor.putBoolean("EnableVibrateAll", !enabled);
|
|
|
|
} else if (i == 8) {
|
|
|
|
enabled = preferences.getBoolean("EnableVibrateGroup", true);
|
|
|
|
editor.putBoolean("EnableVibrateGroup", !enabled);
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
|
|
|
} else if (i == 4 || i == 9) {
|
2014-03-26 20:16:28 +00:00
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
try {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
|
|
|
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
|
|
|
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
|
2014-03-22 22:31:55 +00:00
|
|
|
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
|
|
|
|
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
|
2013-12-20 19:25:49 +00:00
|
|
|
Uri currentSound = null;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
String defaultPath = null;
|
|
|
|
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
|
|
|
|
if (defaultUri != null) {
|
|
|
|
defaultPath = defaultUri.getPath();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
if (i == 4) {
|
|
|
|
String path = preferences.getString("GlobalSoundPath", defaultPath);
|
|
|
|
if (path != null && !path.equals("NoSound")) {
|
|
|
|
if (path.equals(defaultPath)) {
|
|
|
|
currentSound = defaultUri;
|
|
|
|
} else {
|
|
|
|
currentSound = Uri.parse(path);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
} else if (i == 9) {
|
|
|
|
String path = preferences.getString("GroupSoundPath", defaultPath);
|
|
|
|
if (path != null && !path.equals("NoSound")) {
|
|
|
|
if (path.equals(defaultPath)) {
|
|
|
|
currentSound = defaultUri;
|
|
|
|
} else {
|
|
|
|
currentSound = Uri.parse(path);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
|
2014-03-26 20:16:28 +00:00
|
|
|
parentActivity.startActivityForResult(tmpIntent, i);
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-03-23 12:12:13 +00:00
|
|
|
} else if (i == 19) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (reseting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reseting = true;
|
|
|
|
TLRPC.TL_account_resetNotifySettings req = new TLRPC.TL_account_resetNotifySettings();
|
2014-03-22 22:31:55 +00:00
|
|
|
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
|
|
|
Utilities.RunOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().enableJoined = true;
|
2013-12-20 19:25:49 +00:00
|
|
|
ActionBarActivity inflaterActivity = parentActivity;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (inflaterActivity == null) {
|
2013-12-20 19:25:49 +00:00
|
|
|
inflaterActivity = (ActionBarActivity)getActivity();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
if (inflaterActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reseting = false;
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.clear();
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
|
|
|
Toast toast = Toast.makeText(inflaterActivity, R.string.ResetNotificationsText, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
|
|
|
} else if (i == 11) {
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
boolean enabled = preferences.getBoolean("EnableInAppSounds", true);
|
|
|
|
editor.putBoolean("EnableInAppSounds", !enabled);
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
|
|
|
} else if (i == 12) {
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
boolean enabled = preferences.getBoolean("EnableInAppVibrate", true);
|
|
|
|
editor.putBoolean("EnableInAppVibrate", !enabled);
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
|
|
|
} else if (i == 13) {
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
boolean enabled = preferences.getBoolean("EnableInAppPreview", true);
|
|
|
|
editor.putBoolean("EnableInAppPreview", !enabled);
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == 15) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
boolean enabled = preferences.getBoolean("EnableContactJoined", true);
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().enableJoined = !enabled;
|
2014-02-04 18:36:55 +00:00
|
|
|
editor.putBoolean("EnableContactJoined", !enabled);
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
2014-03-23 12:12:13 +00:00
|
|
|
} else if (i == 17) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
boolean enabled = preferences.getBoolean("EnablePebbleNotifications", false);
|
|
|
|
editor.putBoolean("EnablePebbleNotifications", !enabled);
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
listView.setOnTouchListener(new OnSwipeTouchListener() {
|
|
|
|
public void onSwipeRight() {
|
|
|
|
finishFragment(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-26 20:16:28 +00:00
|
|
|
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
|
|
|
String name = null;
|
|
|
|
if (ringtone != null && parentActivity != null) {
|
|
|
|
Ringtone rng = RingtoneManager.getRingtone(parentActivity, ringtone);
|
|
|
|
if (rng != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
if(ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
|
|
|
|
name = LocaleController.getString("Default", R.string.Default);
|
|
|
|
} else {
|
|
|
|
name = rng.getTitle(parentActivity);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
rng.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
|
|
|
|
if (requestCode == 4) {
|
|
|
|
if (name != null && ringtone != null) {
|
|
|
|
editor.putString("GlobalSound", name);
|
|
|
|
editor.putString("GlobalSoundPath", ringtone.toString());
|
|
|
|
} else {
|
|
|
|
editor.putString("GlobalSound", "NoSound");
|
|
|
|
editor.putString("GlobalSoundPath", "NoSound");
|
|
|
|
}
|
|
|
|
} else if (requestCode == 9) {
|
|
|
|
if (name != null && ringtone != null) {
|
|
|
|
editor.putString("GroupSound", name);
|
|
|
|
editor.putString("GroupSoundPath", ringtone.toString());
|
|
|
|
} else {
|
|
|
|
editor.putString("GroupSound", "NoSound");
|
|
|
|
editor.putString("GroupSoundPath", "NoSound");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void applySelfActionBar() {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ActionBar actionBar = parentActivity.getSupportActionBar();
|
|
|
|
actionBar.setDisplayShowTitleEnabled(true);
|
|
|
|
actionBar.setDisplayShowHomeEnabled(false);
|
|
|
|
actionBar.setSubtitle(null);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
actionBar.setDisplayUseLogoEnabled(false);
|
|
|
|
actionBar.setDisplayShowCustomEnabled(false);
|
|
|
|
actionBar.setCustomView(null);
|
2014-03-22 22:31:55 +00:00
|
|
|
actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (title == null) {
|
|
|
|
final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
|
|
|
|
title = (TextView)parentActivity.findViewById(subtitleId);
|
|
|
|
}
|
|
|
|
if (title != null) {
|
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
title.setCompoundDrawablePadding(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (isFinish) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
if (getActivity() == null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-04 20:04:57 +00:00
|
|
|
((LaunchActivity)parentActivity).showActionBar();
|
|
|
|
((LaunchActivity)parentActivity).updateActionBar();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-20 19:25:49 +00:00
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2013-10-25 15:19:00 +00:00
|
|
|
int itemId = item.getItemId();
|
|
|
|
switch (itemId) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finishFragment();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ListAdapter extends BaseAdapter {
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int i) {
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean enabledAll = preferences.getBoolean("EnableAll", true);
|
2014-03-23 12:12:13 +00:00
|
|
|
if (i == 19 || i == 15) {
|
2014-02-04 18:36:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-23 12:12:13 +00:00
|
|
|
return !(i != 1 && !enabledAll && i != 13) && (i > 0 && i < 5 || i > 5 && i < 10 || i > 10 && i < 14) || i == 17;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2014-03-23 12:12:13 +00:00
|
|
|
return 20;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int i) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasStableIds() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
|
int type = getItemViewType(i);
|
|
|
|
if (type == 0) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.settings_section_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_section_text);
|
|
|
|
if (i == 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("MessageNotifications", R.string.MessageNotifications));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == 5) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("GroupNotifications", R.string.GroupNotifications));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == 10) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("InAppNotifications", R.string.InAppNotifications));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == 14) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("Events", R.string.Events));
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == 16) {
|
2014-03-23 12:12:13 +00:00
|
|
|
textView.setText(LocaleController.getString("Pebble", R.string.Pebble));
|
|
|
|
} else if (i == 18) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("Reset", R.string.Reset));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} if (type == 1) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.settings_row_check_notify_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
|
|
|
|
View divider = view.findViewById(R.id.settings_row_divider);
|
|
|
|
|
|
|
|
ImageView checkButton = (ImageView)view.findViewById(R.id.settings_row_check_button);
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean enabled = false;
|
|
|
|
boolean enabledAll = preferences.getBoolean("EnableAll", true);
|
|
|
|
|
|
|
|
if (i == 1 || i == 6) {
|
|
|
|
if (i == 1) {
|
|
|
|
enabled = enabledAll;
|
|
|
|
} else if (i == 6) {
|
|
|
|
enabled = preferences.getBoolean("EnableGroup", true);
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("Alert", R.string.Alert));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
} else if (i == 2 || i == 7) {
|
|
|
|
if (i == 2) {
|
|
|
|
enabled = preferences.getBoolean("EnablePreviewAll", true);
|
|
|
|
} else if (i == 7) {
|
|
|
|
enabled = preferences.getBoolean("EnablePreviewGroup", true);
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("MessagePreview", R.string.MessagePreview));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
} else if (i == 3 || i == 8) {
|
|
|
|
if (i == 3) {
|
|
|
|
enabled = preferences.getBoolean("EnableVibrateAll", true);
|
|
|
|
} else if (i == 8) {
|
|
|
|
enabled = preferences.getBoolean("EnableVibrateGroup", true);
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("Vibrate", R.string.Vibrate));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
} else if (i == 11) {
|
|
|
|
enabled = preferences.getBoolean("EnableInAppSounds", true);
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("InAppSounds", R.string.InAppSounds));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
} else if (i == 12) {
|
|
|
|
enabled = preferences.getBoolean("EnableInAppVibrate", true);
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("InAppVibrate", R.string.InAppVibrate));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
} else if (i == 13) {
|
|
|
|
enabled = preferences.getBoolean("EnableInAppPreview", true);
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("InAppPreview", R.string.InAppPreview));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.INVISIBLE);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == 15) {
|
|
|
|
enabled = preferences.getBoolean("EnableContactJoined", true);
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("ContactJoined", R.string.ContactJoined));
|
2014-02-04 18:36:55 +00:00
|
|
|
divider.setVisibility(View.INVISIBLE);
|
2014-03-23 12:12:13 +00:00
|
|
|
} else if (i == 17) {
|
|
|
|
enabled = preferences.getBoolean("EnablePebbleNotifications", false);
|
|
|
|
textView.setText(LocaleController.getString("Alert", R.string.Alert));
|
|
|
|
divider.setVisibility(View.INVISIBLE);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
if (enabled) {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_on);
|
|
|
|
} else {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_off);
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
if (i != 1 && !enabledAll && i != 15) {
|
2013-10-25 15:19:00 +00:00
|
|
|
view.setEnabled(false);
|
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
checkButton.setAlpha(0.3f);
|
|
|
|
textView.setAlpha(0.3f);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
checkButton.setAlpha(1.0f);
|
|
|
|
textView.setAlpha(1.0f);
|
|
|
|
}
|
|
|
|
view.setEnabled(true);
|
|
|
|
}
|
|
|
|
} else if (type == 2) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.settings_row_detail_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
|
|
|
|
TextView textViewDetail = (TextView)view.findViewById(R.id.settings_row_text_detail);
|
|
|
|
View divider = view.findViewById(R.id.settings_row_divider);
|
2013-11-04 12:31:01 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean enabledAll = preferences.getBoolean("EnableAll", true);
|
|
|
|
if (i == 4 || i == 9) {
|
|
|
|
if (i == 4) {
|
2014-03-22 22:31:55 +00:00
|
|
|
String name = preferences.getString("GlobalSound", LocaleController.getString("Default", R.string.Default));
|
2013-10-25 15:19:00 +00:00
|
|
|
if (name.equals("NoSound")) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textViewDetail.setText(LocaleController.getString("NoSound", R.string.NoSound));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
textViewDetail.setText(name);
|
|
|
|
}
|
|
|
|
} else if (i == 9) {
|
2014-03-22 22:31:55 +00:00
|
|
|
String name = preferences.getString("GroupSound", LocaleController.getString("Default", R.string.Default));
|
2013-10-25 15:19:00 +00:00
|
|
|
if (name.equals("NoSound")) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textViewDetail.setText(LocaleController.getString("NoSound", R.string.NoSound));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
textViewDetail.setText(name);
|
|
|
|
}
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("Sound", R.string.Sound));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.INVISIBLE);
|
2014-03-23 12:12:13 +00:00
|
|
|
} else if (i == 19) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("ResetAllNotifications", R.string.ResetAllNotifications));
|
|
|
|
textViewDetail.setText(LocaleController.getString("UndoAllCustom", R.string.UndoAllCustom));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2014-03-23 12:12:13 +00:00
|
|
|
if (i != 19 && !enabledAll) {
|
2013-10-25 15:19:00 +00:00
|
|
|
view.setEnabled(false);
|
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
textView.setAlpha(0.3f);
|
|
|
|
textViewDetail.setAlpha(0.3f);
|
|
|
|
divider.setAlpha(0.3f);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
textView.setAlpha(1.0f);
|
|
|
|
textViewDetail.setAlpha(1.0f);
|
|
|
|
divider.setAlpha(1.0f);
|
|
|
|
}
|
|
|
|
view.setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
2014-03-23 12:12:13 +00:00
|
|
|
if (i == 0 || i == 5 || i == 10 || i == 14 || i == 16 || i == 18) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 0;
|
2014-03-23 12:12:13 +00:00
|
|
|
} else if (i > 0 && i < 4 || i > 5 && i < 9 || i > 10 && i < 14 || i == 15 || i == 17) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|