don't show unavailable quick actions in settings

This commit is contained in:
Daniel Gultsch 2016-12-06 23:44:39 +01:00
parent 1739af2a41
commit 8eb292d16a

View File

@ -15,6 +15,7 @@ import android.preference.Preference;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.provider.MediaStore;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@ -92,6 +93,27 @@ public class SettingsActivity extends XmppActivity implements
} }
} }
boolean removeLocation = new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null;
boolean removeVoice = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null;
ListPreference quickAction = (ListPreference) mSettingsFragment.findPreference("quick_action");
if (quickAction != null && (removeLocation || removeVoice)) {
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(quickAction.getEntries()));
ArrayList<CharSequence> entryValues = new ArrayList<>(Arrays.asList(quickAction.getEntryValues()));
int index = entryValues.indexOf("location");
if (index > 0 && removeLocation) {
entries.remove(index);
entryValues.remove(index);
}
index = entryValues.indexOf("voice");
if (index > 0 && removeVoice) {
entries.remove(index);
entryValues.remove(index);
}
quickAction.setEntries(entries.toArray(new CharSequence[entries.size()]));
quickAction.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
}
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates"); final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
removeCertsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { removeCertsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override @Override