Commit d22a1060 authored by Geoffrey Métais's avatar Geoffrey Métais

Remove static instance of AdvOptionsDialog

Use a WeakHandler instead, with owner reference
parent 11b08c2b
...@@ -56,6 +56,7 @@ import org.videolan.vlc.interfaces.IDelayController; ...@@ -56,6 +56,7 @@ import org.videolan.vlc.interfaces.IDelayController;
import org.videolan.vlc.util.Strings; import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util; import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance; import org.videolan.vlc.util.VLCInstance;
import org.videolan.vlc.util.WeakHandler;
import java.util.Calendar; import java.util.Calendar;
...@@ -95,7 +96,6 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -95,7 +96,6 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
private Spinner mChapters; private Spinner mChapters;
private TextView mChaptersTitle; private TextView mChaptersTitle;
private static AdvOptionsDialog sInstance;
private int mTextColor; private int mTextColor;
private IDelayController mDelayController; private IDelayController mDelayController;
...@@ -106,7 +106,6 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -106,7 +106,6 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, R.attr.advanced_options_style); setStyle(DialogFragment.STYLE_NO_FRAME, R.attr.advanced_options_style);
sInstance = this;
if (VLCApplication.sPlayerSleepTime != null && VLCApplication.sPlayerSleepTime.before(Calendar.getInstance())) if (VLCApplication.sPlayerSleepTime != null && VLCApplication.sPlayerSleepTime.before(Calendar.getInstance()))
VLCApplication.sPlayerSleepTime = null; VLCApplication.sPlayerSleepTime = null;
mLibVLC = VLCInstance.get(); mLibVLC = VLCInstance.get();
...@@ -297,7 +296,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -297,7 +296,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
public void onFocusChange(View v, boolean hasFocus) { public void onFocusChange(View v, boolean hasFocus) {
if (v instanceof TextView) if (v instanceof TextView)
((TextView) v).setTextColor(v.hasFocus() ? ((TextView) v).setTextColor(v.hasFocus() ?
sInstance.getResources().getColor(R.color.orange500) : mTextColor); getResources().getColor(R.color.orange500) : mTextColor);
} }
}; };
...@@ -312,7 +311,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -312,7 +311,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
dismiss(); dismiss();
} }
public static void setSleep(Context context, Calendar time) { public static void setSleep(Calendar time) {
AlarmManager alarmMgr = (AlarmManager) VLCApplication.getAppContext().getSystemService(Context.ALARM_SERVICE); AlarmManager alarmMgr = (AlarmManager) VLCApplication.getAppContext().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(VLCApplication.SLEEP_INTENT); Intent intent = new Intent(VLCApplication.SLEEP_INTENT);
PendingIntent sleepPendingIntent = PendingIntent.getBroadcast(VLCApplication.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent sleepPendingIntent = PendingIntent.getBroadcast(VLCApplication.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
...@@ -326,26 +325,32 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -326,26 +325,32 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
VLCApplication.sPlayerSleepTime = time; VLCApplication.sPlayerSleepTime = time;
} }
private final static Handler mHandler = new Handler(){ private final Handler mHandler = new AdvOptionsDialogHandler(this);
private static class AdvOptionsDialogHandler extends WeakHandler<AdvOptionsDialog> {
public boolean retry = true; public boolean retry = true;
public AdvOptionsDialogHandler(AdvOptionsDialog owner) {
super(owner);
}
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
String text = null; String text = null;
switch (msg.what) { switch (msg.what) {
case SPEED_TEXT: case SPEED_TEXT:
text = (String) msg.obj; text = (String) msg.obj;
sInstance.mSpeedTv.setText(text); getOwner().mSpeedTv.setText(text);
break; break;
case TOGGLE_CANCEL: case TOGGLE_CANCEL:
sInstance.mSleepCancel.setVisibility(VLCApplication.sPlayerSleepTime == null ? View.GONE : View.VISIBLE); getOwner().mSleepCancel.setVisibility(VLCApplication.sPlayerSleepTime == null ? View.GONE : View.VISIBLE);
case SLEEP_TEXT: case SLEEP_TEXT:
if (VLCApplication.sPlayerSleepTime != null) if (VLCApplication.sPlayerSleepTime != null)
text = DateFormat.getTimeFormat(sInstance.mSleepTime.getContext()).format(VLCApplication.sPlayerSleepTime.getTime()); text = DateFormat.getTimeFormat(getOwner().mSleepTime.getContext()).format(VLCApplication.sPlayerSleepTime.getTime());
if (text == null) if (text == null)
text = "none set"; text = "none set";
sInstance.mSleepTime.setText(text); getOwner().mSleepTime.setText(text);
break; break;
case DIALOG_LISTENER: case DIALOG_LISTENER:
DialogFragment newFragment = (DialogFragment) msg.obj; DialogFragment newFragment = (DialogFragment) msg.obj;
...@@ -353,7 +358,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -353,7 +358,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
newFragment.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() { newFragment.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
mHandler.obtainMessage(TOGGLE_CANCEL).sendToTarget(); obtainMessage(TOGGLE_CANCEL).sendToTarget();
} }
}); });
} else if (retry) { } else if (retry) {
...@@ -366,7 +371,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -366,7 +371,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
break; break;
} }
} }
}; }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -385,7 +390,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList ...@@ -385,7 +390,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
showTimePicker(TimePickerDialogFragment.ACTION_SLEEP); showTimePicker(TimePickerDialogFragment.ACTION_SLEEP);
break; break;
case R.id.sleep_timer_cancel: case R.id.sleep_timer_cancel:
setSleep(v.getContext(), null); setSleep(null);
mHandler.sendEmptyMessage(TOGGLE_CANCEL); mHandler.sendEmptyMessage(TOGGLE_CANCEL);
break; break;
case R.id.playback_switch_audio: case R.id.playback_switch_audio:
......
...@@ -89,7 +89,7 @@ public class TimePickerDialogFragment extends DialogFragment implements TimePick ...@@ -89,7 +89,7 @@ public class TimePickerDialogFragment extends DialogFragment implements TimePick
if (sleepTime.before(currentTime)) if (sleepTime.before(currentTime))
sleepTime.add(Calendar.DATE, 1); sleepTime.add(Calendar.DATE, 1);
AdvOptionsDialog.setSleep(view.getContext(), sleepTime); AdvOptionsDialog.setSleep(sleepTime);
break; break;
case ACTION_JUMP: case ACTION_JUMP:
long time = ( hourOfDay * 60l + minute ) * 60000l; long time = ( hourOfDay * 60l + minute ) * 60000l;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment