1 package com.moiseum.wolnelektury.view.settings;
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;
12 import com.moiseum.wolnelektury.R;
13 import com.moiseum.wolnelektury.base.mvp.PresenterFragment;
14 import com.moiseum.wolnelektury.view.supportus.SupportUsActivity;
16 import butterknife.BindView;
17 import butterknife.OnCheckedChanged;
18 import butterknife.OnClick;
20 public class SettingsFragment extends PresenterFragment<SettingsPresenter> implements SettingsView {
22 public static SettingsFragment newInstance() {
23 return new SettingsFragment();
26 @BindView(R.id.swNotifications)
27 SwitchCompat swNotifications;
28 @BindView(R.id.tvState)
30 @BindView(R.id.btnBecomeAFriend)
31 Button btnBecomeAFriend;
33 private ProgressDialog progressDialog;
36 protected SettingsPresenter createPresenter() {
37 return new SettingsPresenter(this);
41 public int getLayoutResourceId() {
42 return R.layout.fragment_settings;
46 public void prepareView(View view, Bundle savedInstanceState) {
49 @OnClick(R.id.btnBecomeAFriend)
50 public void onBecomeAFriendClicked() {
54 @OnClick(R.id.btnDelete)
55 public void onDeleteAllClicked() {
56 getPresenter().onDeleteAllClicked();
59 @OnCheckedChanged(R.id.swNotifications)
60 public void onNotificationsCheckedChanged(CompoundButton button, boolean checked) {
61 getPresenter().onNotificationsChanged(checked);
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);
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;
83 public void showDeletionCompleted() {
84 Toast.makeText(getContext(), R.string.all_files_removed, Toast.LENGTH_SHORT).show();
88 public void showDeletionFailed(Throwable error) {
89 Toast.makeText(getContext(), getString(R.string.all_files_failed_to_remove, error.getMessage()), Toast.LENGTH_SHORT).show();