Added Android code
[wl-app.git] / Android / app / src / main / java / com / moiseum / wolnelektury / view / settings / SettingsFragment.java
1 package com.moiseum.wolnelektury.view.settings;
2
3 import android.app.ProgressDialog;
4 import android.os.Bundle;
5 import android.support.v7.widget.SwitchCompat;
6 import android.view.View;
7 import android.widget.Button;
8 import android.widget.CompoundButton;
9 import android.widget.TextView;
10 import android.widget.Toast;
11
12 import com.moiseum.wolnelektury.R;
13 import com.moiseum.wolnelektury.base.mvp.PresenterFragment;
14 import com.moiseum.wolnelektury.view.supportus.SupportUsActivity;
15
16 import butterknife.BindView;
17 import butterknife.OnCheckedChanged;
18 import butterknife.OnClick;
19
20 public class SettingsFragment extends PresenterFragment<SettingsPresenter> implements SettingsView {
21
22         public static SettingsFragment newInstance() {
23                 return new SettingsFragment();
24         }
25
26         @BindView(R.id.swNotifications)
27         SwitchCompat swNotifications;
28         @BindView(R.id.tvState)
29         TextView tvState;
30         @BindView(R.id.btnBecomeAFriend)
31         Button btnBecomeAFriend;
32
33         private ProgressDialog progressDialog;
34
35         @Override
36         protected SettingsPresenter createPresenter() {
37                 return new SettingsPresenter(this);
38         }
39
40         @Override
41         public int getLayoutResourceId() {
42                 return R.layout.fragment_settings;
43         }
44
45         @Override
46         public void prepareView(View view, Bundle savedInstanceState) {
47         }
48
49         @OnClick(R.id.btnBecomeAFriend)
50         public void onBecomeAFriendClicked() {
51                 showPayPalForm();
52         }
53
54         @OnClick(R.id.btnDelete)
55         public void onDeleteAllClicked() {
56                 getPresenter().onDeleteAllClicked();
57         }
58
59         @OnCheckedChanged(R.id.swNotifications)
60         public void onNotificationsCheckedChanged(CompoundButton button, boolean checked) {
61                 getPresenter().onNotificationsChanged(checked);
62         }
63
64         @Override
65         public void initializeSettings(boolean notifications, boolean userPremium) {
66                 swNotifications.setChecked(notifications);
67                 tvState.setText(userPremium ? R.string.active : R.string.inactive);
68                 btnBecomeAFriend.setVisibility(userPremium ? View.GONE : View.VISIBLE);
69         }
70
71         @Override
72         public void showProgressDialog(boolean visible) {
73                 if (visible && progressDialog == null) {
74                         String dialogMessage = getString(R.string.removing_all_files);
75                         progressDialog = ProgressDialog.show(getContext(), null, dialogMessage, true, false);
76                 } else if (!visible && progressDialog != null) {
77                         progressDialog.hide();
78                         progressDialog = null;
79                 }
80         }
81
82         @Override
83         public void showDeletionCompleted() {
84                 Toast.makeText(getContext(), R.string.all_files_removed, Toast.LENGTH_SHORT).show();
85         }
86
87         @Override
88         public void showDeletionFailed(Throwable error) {
89                 Toast.makeText(getContext(), getString(R.string.all_files_failed_to_remove, error.getMessage()), Toast.LENGTH_SHORT).show();
90         }
91 }