· 9 years ago · Feb 29, 2016, 11:33 PM
1public class AuthenticationActivity extends AppCompatActivity implements IAuthenticationActivity {
2FragmentManager mgr;
3
4@Override
5protected void onCreate(Bundle savedInstanceState) {
6 super.onCreate(savedInstanceState);
7 setContentView(R.layout.activity_authentication);
8 Fragment loginFragment = new LoginFragment();
9 mgr = getSupportFragmentManager();
10 FragmentTransaction trans = mgr.beginTransaction();
11 trans.add(R.id.authparent, loginFragment, Constants.LOGIN_FRAGMENT);
12 trans.commit();
13}
14
15@Override
16public void onRegisterNewUser() {
17 Fragment fragment = new RegisterFragment();
18 FragmentTransaction trans = mgr.beginTransaction();
19 trans.replace(R.id.authparent, fragment);
20 trans.addToBackStack(null);
21 trans.commit();
22}
23}
24
25public class LoginFragment extends Fragment {
26
27private static final String TAG = "LoginFragment";
28private LoginViewModel viewModel;
29@Bind(R.id.input_email)
30EditText _emailText;
31@Bind(R.id.input_password) EditText _passwordText;
32@Bind(R.id.btn_login)
33Button _loginButton;
34@Bind(R.id.link_signup)
35TextView _signupLink;
36@Bind(R.id.login_progress)
37ProgressBar _progressBar;
38
39@Override
40public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
41 View view = inflater.inflate(R.layout.fragment_login, container, false);
42 ButterKnife.bind(view);
43
44 viewModel = new LoginViewModel(getContext());
45 FragmentLoginBinding binding = DataBindingUtil.setContentView(getActivity(), R.layout.fragment_login);
46 binding.setViewModel(viewModel);
47 return view;
48}
49}
50
51public class RegisterFragment extends Fragment implements IRegisterFragment {
52private OAuthToken oauthToken = null;
53private static final String TAG = "RegisterFragment";
54private RegisterViewModel viewModel;
55@Bind(R.id.input_email)
56EditText _emailText;
57@Bind(R.id.input_username)
58EditText _usernameText;
59@Bind(R.id.input_password)
60EditText _passwordText;
61@Bind(R.id.input_verify_password)
62EditText _verifyPasswordText;
63@Bind(R.id.btn_register)
64Button _registerButton;
65@Bind(R.id.register_progress)
66ProgressBar _progressBar;
67
68@Override
69public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
70 View view = inflater.inflate(R.layout.fragment_register, container, false);
71 ButterKnife.bind(view);
72 viewModel = new RegisterViewModel(getContext());
73 FragmentRegisterBinding binding = DataBindingUtil.setContentView(getActivity(), R.layout.fragment_register);
74 binding.setViewModel(viewModel);
75 return view;
76}
77}
78
79public class LoginViewModel extends ViewModelBase implements ILoginCallBack {
80...
81
82public void onSignupLink(View view) {
83 if (context instanceof IAuthenticationActivity) {
84 ((IAuthenticationActivity) context).onRegisterNewUser();
85 }
86}
87...
88}
89
90public class ViewModelBase extends BaseObservable {
91protected final Context context;
92
93protected Context getContext(){
94 return context;
95}
96
97public ViewModelBase(Context context) {
98 this.context = context;
99}
100
101protected boolean checkEmpty(CharSequence s) {
102 if (s.toString().isEmpty()) {
103 return true;
104 }
105 return false;
106}
107
108<?xml version="1.0" encoding="utf-8"?>
109<RelativeLayout
110xmlns:android="http://schemas.android.com/apk/res/android"
111android:id="@+id/authparent"
112android:layout_width="match_parent"
113android:layout_height="match_parent"
114android:keepScreenOn="true">
115
116</RelativeLayout>
117
118<?xml version="1.0" encoding="utf-8"?>
119<layout xmlns:android="http://schemas.android.com/apk/res/android"
120android:keepScreenOn="true">
121<data>
122 <variable name="viewModel" type="com.savij.splitr.viewmodels.LoginViewModel" />
123</data>
124<ScrollView
125android:layout_width="fill_parent"
126android:layout_height="fill_parent"
127xmlns:app="http://schemas.android.com/apk/res-auto"
128android:fitsSystemWindows="true">
129<RelativeLayout
130android:layout_width="match_parent"
131android:layout_height="match_parent">
132
133 <ProgressBar
134 android:id="@+id/login_progress"
135 android:visibility="@{viewModel.ProgressBarVisibility}"
136 android:layout_width="wrap_content"
137 android:layout_height="wrap_content"
138 android:layout_centerInParent="true"
139 />
140
141<LinearLayout
142 android:orientation="vertical"
143 android:layout_width="match_parent"
144 android:layout_height="wrap_content"
145 android:paddingTop="46dp"
146 android:paddingLeft="24dp"
147 android:paddingRight="24dp"
148 android:layout_alignParentTop="true">
149
150 <ImageView android:src="@drawable/splitr_logo_crop"
151 android:layout_width="wrap_content"
152 android:layout_height="250dp"
153 android:layout_gravity="center_horizontal" />
154 <!--<TextView-->
155 <!--android:layout_width="wrap_content"-->
156 <!--android:layout_height="wrap_content"-->
157 <!--android:text="@string/app_title"-->
158 <!--android:textSize="@dimen/font_title"-->
159 <!--android:layout_marginBottom="24dp"-->
160 <!--android:layout_gravity="center_horizontal" />-->
161
162 <!-- Email Label -->
163 <android.support.design.widget.TextInputLayout
164 android:layout_width="match_parent"
165 android:layout_height="wrap_content"
166 android:layout_marginTop="8dp"
167 android:layout_marginBottom="8dp"
168 app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
169 <EditText android:id="@+id/input_email"
170 android:layout_width="match_parent"
171 android:layout_height="wrap_content"
172 android:inputType="textEmailAddress"
173 android:text="@{viewModel.Email}"
174 android:onTextChanged="@{viewModel.emailChanged}"
175 android:error="@{viewModel.EmailError}"
176 android:hint="Email"
177 android:singleLine="true"/>
178 </android.support.design.widget.TextInputLayout>
179
180 <!-- Password Label -->
181 <android.support.design.widget.TextInputLayout
182 android:layout_width="match_parent"
183 android:layout_height="wrap_content"
184 android:layout_marginTop="8dp"
185 android:layout_marginBottom="8dp"
186 app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
187 <EditText android:id="@+id/input_password"
188 android:layout_width="match_parent"
189 android:layout_height="wrap_content"
190 android:text="@{viewModel.Password}"
191 android:onTextChanged="@{viewModel.passwordChanged}"
192 android:error="@{viewModel.PasswordError}"
193 android:inputType="textPassword"
194 android:hint="Password"
195 android:singleLine="true"/>
196 </android.support.design.widget.TextInputLayout>
197
198 <android.support.v7.widget.AppCompatButton
199 android:id="@+id/btn_login"
200 android:layout_width="fill_parent"
201 android:layout_height="wrap_content"
202 android:layout_marginTop="24dp"
203 android:layout_marginBottom="24dp"
204 android:padding="12dp"
205 android:text="Login"
206 android:onClick="@{viewModel.onClickLogin}"
207 />
208
209 <TextView android:id="@+id/link_signup"
210 android:layout_width="fill_parent"
211 android:layout_height="wrap_content"
212 android:layout_marginBottom="24dp"
213 android:text="No account yet? Create one"
214 android:onClick="@{viewModel.onSignupLink}"
215 android:gravity="center"
216 android:textSize="16dip"/>
217
218 <TextView android:id="@+id/link_lost_password"
219 android:layout_width="fill_parent"
220 android:layout_height="wrap_content"
221 android:layout_marginBottom="24dp"
222 android:text="Forgot password?"
223 android:onClick="@{viewModel.onForgotPassword}"
224 android:gravity="center"
225 android:textSize="16dip"/>
226
227</LinearLayout>
228
229<?xml version="1.0" encoding="utf-8"?>
230<layout xmlns:android="http://schemas.android.com/apk/res/android"
231android:keepScreenOn="true">
232<data>
233 <variable name="viewModel" type="com.savij.splitr.viewmodels.RegisterViewModel" />
234</data>
235<ScrollView
236 android:layout_width="fill_parent"
237 android:layout_height="fill_parent"
238 xmlns:app="http://schemas.android.com/apk/res-auto"
239 android:fitsSystemWindows="true">
240 <RelativeLayout
241 android:layout_width="match_parent"
242 android:layout_height="match_parent">
243
244 <ProgressBar
245 android:id="@+id/register_progress"
246 android:visibility="@{viewModel.ProgressBarVisibility}"
247 android:layout_width="wrap_content"
248 android:layout_height="wrap_content"
249 android:layout_centerInParent="true"
250 />
251
252 <LinearLayout
253 android:orientation="vertical"
254 android:layout_width="match_parent"
255 android:layout_height="wrap_content"
256 android:paddingTop="46dp"
257 android:paddingLeft="24dp"
258 android:paddingRight="24dp"
259 android:layout_alignParentTop="true">
260
261 <ImageView android:src="@drawable/splitr_logo_solo"
262 android:layout_width="wrap_content"
263 android:layout_height="100dp"
264 android:layout_gravity="center_horizontal" />
265
266 <!-- Email Label -->
267 <android.support.design.widget.TextInputLayout
268 android:layout_width="match_parent"
269 android:layout_height="wrap_content"
270 android:layout_marginTop="8dp"
271 android:layout_marginBottom="8dp"
272 app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
273 <EditText android:id="@+id/input_email"
274 android:layout_width="match_parent"
275 android:layout_height="wrap_content"
276 android:inputType="textEmailAddress"
277 android:text="@{viewModel.Email}"
278 android:onTextChanged="@{viewModel.emailChanged}"
279 android:error="@{viewModel.EmailError}"
280 android:hint="Email"
281 android:singleLine="true"/>
282 </android.support.design.widget.TextInputLayout>
283
284 <android.support.design.widget.TextInputLayout
285 android:layout_width="match_parent"
286 android:layout_height="wrap_content"
287 android:layout_marginTop="8dp"
288 android:layout_marginBottom="8dp"
289 app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
290 <EditText android:id="@+id/input_username"
291 android:layout_width="match_parent"
292 android:layout_height="wrap_content"
293 android:inputType="textEmailAddress"
294 android:text="@{viewModel.Username}"
295 android:onTextChanged="@{viewModel.usernameChanged}"
296 android:error="@{viewModel.UsernameError}"
297 android:hint="Username"
298 android:singleLine="true"/>
299 </android.support.design.widget.TextInputLayout>
300
301 <!-- Password Label -->
302 <android.support.design.widget.TextInputLayout
303 android:layout_width="match_parent"
304 android:layout_height="wrap_content"
305 android:layout_marginTop="8dp"
306 android:layout_marginBottom="8dp"
307 app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
308 <EditText android:id="@+id/input_password"
309 android:layout_width="match_parent"
310 android:layout_height="wrap_content"
311 android:text="@{viewModel.Password}"
312 android:onTextChanged="@{viewModel.passwordChanged}"
313 android:error="@{viewModel.PasswordError}"
314 android:inputType="textPassword"
315 android:hint="Password"
316 android:singleLine="true"/>
317 </android.support.design.widget.TextInputLayout>
318
319 <android.support.design.widget.TextInputLayout
320 android:layout_width="match_parent"
321 android:layout_height="wrap_content"
322 android:layout_marginTop="8dp"
323 android:layout_marginBottom="8dp"
324 app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
325 <EditText android:id="@+id/input_verify_password"
326 android:layout_width="match_parent"
327 android:layout_height="wrap_content"
328 android:text="@{viewModel.VerifyPassword}"
329 android:onTextChanged="@{viewModel.verifyPasswordChanged}"
330 android:error="@{viewModel.VerifyPasswordError}"
331 android:inputType="textPassword"
332 android:hint="Verify Password"
333 android:singleLine="true"/>
334 </android.support.design.widget.TextInputLayout>
335
336 <android.support.v7.widget.AppCompatButton
337 android:id="@+id/btn_register"
338 android:layout_width="fill_parent"
339 android:layout_height="wrap_content"
340 android:layout_marginTop="24dp"
341 android:layout_marginBottom="24dp"
342 android:padding="12dp"
343 android:text="Login"
344 android:onClick="@{viewModel.onClickRegister}"
345 />
346
347 <TextView android:id="@+id/link_signup"
348 android:layout_width="fill_parent"
349 android:layout_height="wrap_content"
350 android:layout_marginBottom="24dp"
351 android:text="Already have an account?"
352 android:onClick="@{viewModel.onLoginLink}"
353 android:gravity="center"
354 android:textSize="16dip"/>
355
356 </LinearLayout>
357
358 </RelativeLayout>
359
360</ScrollView>
361</layout>
362
36302-29 17:23:24.340 8064-8064/com.savij.splitr E/FragmentManager: Activity state:
36402-29 17:23:24.370 8064-8064/com.savij.splitr E/AndroidRuntime: FATAL EXCEPTION: main
365Process: com.savij.splitr, PID: 8064
366java.lang.IllegalArgumentException: No view found for id 0x7f0c006c (com.savij.splitr:id/authparent) for fragment RegisterFragment{a34c76c #1 id=0x7f0c006c}
367at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1059)
368at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
369at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
370at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
371at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
372at android.os.Handler.handleCallback(Handler.java:739)
373at android.os.Handler.dispatchMessage(Handler.java:95)
374at android.os.Looper.loop(Looper.java:145)
375at android.app.ActivityThread.main(ActivityThread.java:5835)
376at java.lang.reflect.Method.invoke(Native Method)
377at java.lang.reflect.Method.invoke(Method.java:372)
378at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
379at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)