2015-06-09 07:37:20 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.NonNull;
|
2017-10-16 13:11:42 -07:00
|
|
|
import android.support.annotation.Nullable;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.support.v4.app.ListFragment;
|
|
|
|
import android.support.v4.app.LoaderManager;
|
|
|
|
import android.support.v4.content.Loader;
|
|
|
|
import android.support.v4.widget.CursorAdapter;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.BlockedContactsLoader;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.preferences.BlockedContactListItem;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
|
|
|
|
|
|
|
public class BlockedContactsActivity extends PassphraseRequiredActionBarActivity {
|
|
|
|
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreCreate() {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2018-02-01 19:22:48 -08:00
|
|
|
public void onCreate(Bundle bundle, boolean ready) {
|
2015-06-09 07:37:20 -07:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
getSupportActionBar().setTitle(R.string.BlockedContactsActivity_blocked_contacts);
|
2018-02-01 19:22:48 -08:00
|
|
|
initFragment(android.R.id.content, new BlockedContactsFragment());
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home: finish(); return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class BlockedContactsFragment
|
|
|
|
extends ListFragment
|
|
|
|
implements LoaderManager.LoaderCallbacks<Cursor>, ListView.OnItemClickListener
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
|
|
|
return inflater.inflate(R.layout.blocked_contacts_fragment, container, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle bundle) {
|
|
|
|
super.onCreate(bundle);
|
2017-10-16 13:11:42 -07:00
|
|
|
setListAdapter(new BlockedContactAdapter(getActivity(), GlideApp.with(this), null));
|
2015-06-09 07:37:20 -07:00
|
|
|
getLoaderManager().initLoader(0, null, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle bundle) {
|
|
|
|
super.onActivityCreated(bundle);
|
|
|
|
getListView().setOnItemClickListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
|
|
|
return new BlockedContactsLoader(getActivity());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
|
|
|
if (getListAdapter() != null) {
|
|
|
|
((CursorAdapter) getListAdapter()).changeCursor(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> loader) {
|
|
|
|
if (getListAdapter() != null) {
|
|
|
|
((CursorAdapter) getListAdapter()).changeCursor(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
2017-08-01 08:56:00 -07:00
|
|
|
Recipient recipient = ((BlockedContactListItem)view).getRecipient();
|
|
|
|
Intent intent = new Intent(getActivity(), RecipientPreferenceActivity.class);
|
|
|
|
intent.putExtra(RecipientPreferenceActivity.ADDRESS_EXTRA, recipient.getAddress());
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class BlockedContactAdapter extends CursorAdapter {
|
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
private final GlideRequests glideRequests;
|
|
|
|
|
|
|
|
BlockedContactAdapter(@NonNull Context context, @NonNull GlideRequests glideRequests, @Nullable Cursor c) {
|
2015-06-09 07:37:20 -07:00
|
|
|
super(context, c);
|
2017-10-16 13:11:42 -07:00
|
|
|
this.glideRequests = glideRequests;
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
|
|
return LayoutInflater.from(context)
|
|
|
|
.inflate(R.layout.blocked_contact_list_item, parent, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void bindView(View view, Context context, Cursor cursor) {
|
2017-08-01 08:56:00 -07:00
|
|
|
String address = cursor.getString(1);
|
2017-08-21 18:32:38 -07:00
|
|
|
Recipient recipient = Recipient.from(context, Address.fromSerialized(address), true);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
((BlockedContactListItem) view).set(glideRequests, recipient);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|