mirror of
https://github.com/balkian/Carrousel-Android.git
synced 2024-12-22 21:18:13 +00:00
I13: recibir lista de subscritos
This commit is contained in:
parent
a1b30d37e9
commit
aaf212fda3
@ -44,6 +44,11 @@ public class Configuration extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||||
mResults = ((Results.LocalBinder)service).getService();
|
mResults = ((Results.LocalBinder)service).getService();
|
||||||
|
subscribedMatches = mResults.getSubscriptions();
|
||||||
|
if (subscribedMatches == null) {
|
||||||
|
subscribedMatches = new HashSet<String>();
|
||||||
|
} else
|
||||||
|
mSubscribeButton.setEnabled(true);
|
||||||
populateMatches();
|
populateMatches();
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
|
|
||||||
@ -106,12 +111,13 @@ public class Configuration extends ListActivity {
|
|||||||
private CheckBox mCb;
|
private CheckBox mCb;
|
||||||
private CompoundButton.OnCheckedChangeListener mListener = null;
|
private CompoundButton.OnCheckedChangeListener mListener = null;
|
||||||
|
|
||||||
public MatchView(Context context, String text) {
|
public MatchView(Context context, String text, boolean isChecked) {
|
||||||
super(context);
|
super(context);
|
||||||
this.setOrientation(HORIZONTAL);
|
this.setOrientation(HORIZONTAL);
|
||||||
mTv = new TextView(context);
|
mTv = new TextView(context);
|
||||||
mTv.setText(text);
|
mTv.setText(text);
|
||||||
mCb = new CheckBox(context);
|
mCb = new CheckBox(context);
|
||||||
|
setChecked(isChecked);
|
||||||
mCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
mCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
@ -127,6 +133,10 @@ public class Configuration extends ListActivity {
|
|||||||
mTv.setText(text);
|
mTv.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setChecked(boolean isChecked) {
|
||||||
|
mCb.setChecked(isChecked);
|
||||||
|
}
|
||||||
|
|
||||||
public void setOnMatchCheckedChanged(CompoundButton.OnCheckedChangeListener listener) {
|
public void setOnMatchCheckedChanged(CompoundButton.OnCheckedChangeListener listener) {
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
}
|
}
|
||||||
@ -152,14 +162,25 @@ public class Configuration extends ListActivity {
|
|||||||
public long getItemId(int pos) {
|
public long getItemId(int pos) {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public View getView(int pos, View convertView, ViewGroup parent) {
|
public View getView(int pos, View convertView, ViewGroup parent) {
|
||||||
MatchView v;
|
MatchView v;
|
||||||
|
Match match = mMatches[pos];
|
||||||
|
boolean isSubscribed = subscribedMatches.contains(match.getId());
|
||||||
|
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
v = new MatchView(parent.getContext(), mMatches[pos].toString());
|
; v = new MatchView(parent.getContext(), match.toString(), isSubscribed);
|
||||||
v.setOnMatchCheckedChanged(new OnMatchCheckedListener(pos));
|
v.setOnMatchCheckedChanged(new OnMatchCheckedListener(pos));
|
||||||
} else {
|
} else {
|
||||||
v = (MatchView)convertView;
|
v = (MatchView)convertView;
|
||||||
v.setText(mMatches[pos].toString());
|
v.setText(match.toString());
|
||||||
|
// This is tricky: We are reusing the view for a different match.
|
||||||
|
// We need to update the view checkbox state and we use setChecked,
|
||||||
|
// but this would trigger the previous event listener, clearing
|
||||||
|
// the model of the previous item shown with this view.
|
||||||
|
v.setOnMatchCheckedChanged(null);
|
||||||
|
v.setChecked(isSubscribed);
|
||||||
|
v.setOnMatchCheckedChanged(new OnMatchCheckedListener(pos));
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@ -173,9 +194,10 @@ public class Configuration extends ListActivity {
|
|||||||
Match m = (Match)getItem(mPosition);
|
Match m = (Match)getItem(mPosition);
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
if (isChecked)
|
if (isChecked)
|
||||||
subscribedMatches.remove(mMatches[mPosition].getId());
|
|
||||||
else
|
|
||||||
subscribedMatches.add(mMatches[mPosition].getId());
|
subscribedMatches.add(mMatches[mPosition].getId());
|
||||||
|
else
|
||||||
|
subscribedMatches.remove(mMatches[mPosition].getId());
|
||||||
|
mSubscribeButton.setEnabled(!subscribedMatches.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,11 @@ public class Results extends Service {
|
|||||||
mSubscriptions = subscriptions;
|
mSubscriptions = subscriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getSubscriptions() {
|
||||||
|
return mSubscriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
Results getService() {
|
Results getService() {
|
||||||
return Results.this;
|
return Results.this;
|
||||||
|
Loading…
Reference in New Issue
Block a user