-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathSetupSelectBackendFragment.java
More file actions
96 lines (82 loc) · 3.21 KB
/
SetupSelectBackendFragment.java
File metadata and controls
96 lines (82 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright 2003-2020 The Kegbot Project contributors <info@kegbot.org>
*
* This file is part of the Kegtab package from the Kegbot project. For
* more information on Kegtab or Kegbot, see <http://kegbot.org/>.
*
* Kegtab is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, version 2.
*
* Kegtab is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with Kegtab. If not, see <http://www.gnu.org/licenses/>.
*/
package org.kegbot.app.setup;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import org.kegbot.app.KegbotApplication;
import org.kegbot.app.R;
import org.kegbot.app.config.AppConfiguration;
import butterknife.ButterKnife;
/**
* Shows a choice of
*/
public class SetupSelectBackendFragment extends SetupFragment {
private View mView;
private final DialogFragment mDialogFragment = new DialogFragment() {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.setup_select_backend_local_warning_title);
builder.setMessage(R.string.setup_select_backend_local_warning_description);
builder.setPositiveButton(R.string.setup_select_backend_local_warning_ok, null);
builder.setCancelable(false);
return builder.create();
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.setup_select_backend_fragment, null);
final RadioGroup group = ButterKnife.findById(mView, R.id.backend_group);
final AppConfiguration prefs = ((KegbotApplication) getActivity().getApplication()).getConfig();
if (prefs.isLocalBackend()) {
group.check(R.id.radio_backend_local);
} else {
group.check(R.id.radio_backend_server);
}
final RadioButton button = ButterKnife.findById(mView, R.id.radio_backend_local);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDialogFragment.show(getFragmentManager(), null);
}
});
return mView;
}
@Override
public String validate() {
final AppConfiguration prefs = ((KegbotApplication) getActivity().getApplication()).getConfig();
final RadioGroup group = ButterKnife.findById(mView, R.id.backend_group);
final int checkedId = group.getCheckedRadioButtonId();
if (checkedId == R.id.radio_backend_local) {
prefs.setIsLocalBackend(true);
} else if (checkedId == R.id.radio_backend_server) {
prefs.setIsLocalBackend(false);
} else {
return "Please select one of the backend modes.";
}
return "";
}
}