2018-04-04 07:33:07 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2019-01-05 09:31:06 +00:00
|
|
|
import android.content.ComponentName;
|
2018-04-04 07:33:07 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.v7.app.ActionBar;
|
2019-01-05 09:31:06 +00:00
|
|
|
import android.util.Log;
|
2018-04-04 07:33:07 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
2019-01-05 09:31:06 +00:00
|
|
|
import java.util.Arrays;
|
2018-04-04 07:33:07 +00:00
|
|
|
import java.util.Collections;
|
2019-01-05 09:31:06 +00:00
|
|
|
import java.util.List;
|
2018-04-04 07:33:07 +00:00
|
|
|
|
2019-01-05 09:31:06 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2018-04-04 07:33:07 +00:00
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.ListItem;
|
|
|
|
|
2019-01-05 09:31:06 +00:00
|
|
|
public class ShortcutActivity extends AbstractSearchableListItemActivity {
|
|
|
|
|
|
|
|
private static final List<String> BLACKLISTED_ACTIVITIES = Arrays.asList("com.teslacoilsw.launcher.ChooseActionIntentActivity");
|
2018-04-04 07:33:07 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void refreshUiReal() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
getListView().setOnItemClickListener((parent, view, position, id) -> {
|
2019-01-05 09:31:06 +00:00
|
|
|
|
|
|
|
final ComponentName callingActivity = getCallingActivity();
|
|
|
|
|
2018-04-04 07:33:07 +00:00
|
|
|
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
|
|
|
|
|
|
|
|
ListItem listItem = getListItems().get(position);
|
2019-01-05 09:31:06 +00:00
|
|
|
final boolean legacy = BLACKLISTED_ACTIVITIES.contains(callingActivity == null ? null : callingActivity.getClassName());
|
|
|
|
Intent shortcut = xmppConnectionService.getShortcutService().createShortcut(((Contact) listItem), legacy);
|
2018-04-04 07:33:07 +00:00
|
|
|
setResult(RESULT_OK,shortcut);
|
|
|
|
finish();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
ActionBar bar = getSupportActionBar();
|
|
|
|
if(bar != null){
|
|
|
|
bar.setTitle(R.string.create_shortcut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void filterContacts(String needle) {
|
|
|
|
getListItems().clear();
|
|
|
|
if (xmppConnectionService == null) {
|
|
|
|
getListItemAdapter().notifyDataSetChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (final Account account : xmppConnectionService.getAccounts()) {
|
|
|
|
if (account.getStatus() != Account.State.DISABLED) {
|
|
|
|
for (final Contact contact : account.getRoster().getContacts()) {
|
2018-11-03 15:32:08 +00:00
|
|
|
if (contact.showInContactList()
|
2018-04-04 07:33:07 +00:00
|
|
|
&& contact.match(this, needle)) {
|
|
|
|
getListItems().add(contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Collections.sort(getListItems());
|
|
|
|
getListItemAdapter().notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|