7444
|
1 |
package org.hedgewars.hedgeroid;
|
|
2 |
|
|
3 |
import org.hedgewars.hedgeroid.netplay.Netplay;
|
|
4 |
import org.hedgewars.hedgeroid.netplay.Netplay.State;
|
|
5 |
|
|
6 |
import android.app.Dialog;
|
|
7 |
import android.content.BroadcastReceiver;
|
|
8 |
import android.content.Context;
|
|
9 |
import android.content.Intent;
|
|
10 |
import android.content.IntentFilter;
|
|
11 |
import android.support.v4.app.DialogFragment;
|
|
12 |
import android.support.v4.content.LocalBroadcastManager;
|
|
13 |
|
|
14 |
public class ConnectionDependendDialogFragment extends DialogFragment {
|
|
15 |
@Override
|
|
16 |
public void onStart() {
|
|
17 |
super.onStart();
|
|
18 |
LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(dismissReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
|
|
19 |
if(Netplay.getAppInstance(getActivity().getApplicationContext()).getState() == State.NOT_CONNECTED) {
|
|
20 |
dismiss();
|
|
21 |
}
|
|
22 |
}
|
|
23 |
|
|
24 |
@Override
|
|
25 |
public void onStop() {
|
|
26 |
super.onStop();
|
|
27 |
LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(dismissReceiver);
|
|
28 |
}
|
|
29 |
|
|
30 |
private BroadcastReceiver dismissReceiver = new BroadcastReceiver() {
|
|
31 |
@Override
|
|
32 |
public void onReceive(Context context, Intent intent) {
|
|
33 |
Dialog dialog = getDialog();
|
|
34 |
if(dialog != null) {
|
|
35 |
dialog.dismiss();
|
|
36 |
} else {
|
|
37 |
dismiss();
|
|
38 |
}
|
|
39 |
}
|
|
40 |
};
|
|
41 |
}
|