44import android .support .annotation .NonNull ;
55import android .support .v7 .app .AlertDialog ;
66import android .view .View ;
7- import android .widget .ArrayAdapter ;
87import android .widget .ListView ;
98
109import com .blogspot .e_kanivets .moneytracker .MtApp ;
1110import com .blogspot .e_kanivets .moneytracker .R ;
1211import com .blogspot .e_kanivets .moneytracker .activity .base .BaseBackActivity ;
12+ import com .blogspot .e_kanivets .moneytracker .adapter .BackupAdapter ;
1313import com .blogspot .e_kanivets .moneytracker .controller .BackupController ;
1414import com .blogspot .e_kanivets .moneytracker .controller .PreferenceController ;
1515import com .blogspot .e_kanivets .moneytracker .util .AnswersProxy ;
2929public class BackupActivity extends BaseBackActivity {
3030 private static final String APP_KEY = "5lqugcckdy9y6lj" ;
3131
32- @ Inject
33- PreferenceController preferenceController ;
34- @ Inject
35- BackupController backupController ;
32+ @ Inject PreferenceController preferenceController ;
33+ @ Inject BackupController backupController ;
3634
3735 private DbxClientV2 dbClient ;
3836
39- @ BindView (R .id .btn_backup_now )
40- View btnBackupNow ;
41- @ BindView (R .id .list_view )
42- ListView listView ;
37+ @ BindView (R .id .btn_backup_now ) View btnBackupNow ;
38+ @ BindView (R .id .list_view ) ListView listView ;
4339
44- @ Override
45- protected int getContentViewId () {
40+ @ Override protected int getContentViewId () {
4641 return R .layout .activity_backup ;
4742 }
4843
49- @ Override
50- protected boolean initData () {
44+ @ Override protected boolean initData () {
5145 getAppComponent ().inject (BackupActivity .this );
5246
5347 String accessToken = preferenceController .readDropboxAccessToken ();
54- if (accessToken == null ) Auth .startOAuth2Authentication (BackupActivity .this , APP_KEY );
55- else {
48+ if (accessToken == null ) {
49+ Auth .startOAuth2Authentication (BackupActivity .this , APP_KEY );
50+ } else {
5651 DbxRequestConfig config = new DbxRequestConfig ("open_money_tracker" );
5752 dbClient = new DbxClientV2 (config , accessToken );
5853 fetchBackups ();
@@ -61,14 +56,12 @@ protected boolean initData() {
6156 return super .initData ();
6257 }
6358
64- @ Override
65- protected void initViews () {
59+ @ Override protected void initViews () {
6660 super .initViews ();
6761 btnBackupNow .setEnabled (preferenceController .readDropboxAccessToken () != null );
6862 }
6963
70- @ Override
71- protected void onResume () {
64+ @ Override protected void onResume () {
7265 super .onResume ();
7366
7467 if (Auth .getOAuth2Token () != null ) {
@@ -84,13 +77,11 @@ protected void onResume() {
8477 }
8578 }
8679
87- @ OnClick (R .id .btn_backup_now )
88- public void backupNow () {
80+ @ OnClick (R .id .btn_backup_now ) public void backupNow () {
8981 AnswersProxy .get ().logButton ("Make Backup" );
9082 startProgress (getString (R .string .making_backup ));
9183 backupController .makeBackup (dbClient , new BackupController .OnBackupListener () {
92- @ Override
93- public void onBackupSuccess () {
84+ @ Override public void onBackupSuccess () {
9485 AnswersProxy .get ().logEvent ("Backup success" );
9586 Timber .d ("Backup success." );
9687 if (isFinishing ()) return ;
@@ -99,8 +90,7 @@ public void onBackupSuccess() {
9990 fetchBackups ();
10091 }
10192
102- @ Override
103- public void onBackupFailure (String reason ) {
93+ @ Override public void onBackupFailure (String reason ) {
10494 AnswersProxy .get ().logEvent ("Backup failure" );
10595 Timber .d ("Backup failure." );
10696 if (isFinishing ()) return ;
@@ -113,17 +103,15 @@ public void onBackupFailure(String reason) {
113103 });
114104 }
115105
116- @ OnItemClick (R .id .list_view )
117- public void restoreBackupClicked (int position ) {
106+ @ OnItemClick (R .id .list_view ) public void restoreBackupClicked (int position ) {
118107 AnswersProxy .get ().logButton ("Restore backup" );
119108 final String backupName = listView .getAdapter ().getItem (position ).toString ();
120109
121110 AlertDialog .Builder builder = new AlertDialog .Builder (BackupActivity .this );
122111 builder .setTitle (getString (R .string .warning ));
123112 builder .setMessage (getString (R .string .want_erase_and_restore , backupName ));
124113 builder .setPositiveButton (android .R .string .ok , new DialogInterface .OnClickListener () {
125- @ Override
126- public void onClick (DialogInterface dialog , int which ) {
114+ @ Override public void onClick (DialogInterface dialog , int which ) {
127115 restoreBackup (backupName );
128116 }
129117 });
@@ -134,8 +122,7 @@ public void onClick(DialogInterface dialog, int which) {
134122 private void restoreBackup (final String backupName ) {
135123 startProgress (getString (R .string .restoring_backup ));
136124 backupController .restoreBackup (dbClient , backupName , new BackupController .OnRestoreBackupListener () {
137- @ Override
138- public void onRestoreSuccess () {
125+ @ Override public void onRestoreSuccess () {
139126 AnswersProxy .get ().logEvent ("Restore Success" );
140127 Timber .d ("Restore success." );
141128 if (isFinishing ()) return ;
@@ -146,8 +133,7 @@ public void onRestoreSuccess() {
146133 builder .setTitle (getString (R .string .backup_is_restored ));
147134 builder .setMessage (getString (R .string .backup_restored , backupName ));
148135 builder .setOnDismissListener (new DialogInterface .OnDismissListener () {
149- @ Override
150- public void onDismiss (DialogInterface dialog ) {
136+ @ Override public void onDismiss (DialogInterface dialog ) {
151137 MtApp .get ().buildAppComponent ();
152138 setResult (RESULT_OK );
153139 finish ();
@@ -157,32 +143,27 @@ public void onDismiss(DialogInterface dialog) {
157143 builder .show ();
158144 }
159145
160- @ Override
161- public void onRestoreFailure (String reason ) {
146+ @ Override public void onRestoreFailure (String reason ) {
162147 AnswersProxy .get ().logEvent ("Restore Failure" );
163148 Timber .d ("Restore failure." );
164149 if (isFinishing ()) return ;
165150
166151 stopProgress ();
167152 showToast (R .string .failed_restore_backup );
168153
169- if (BackupController .OnRestoreBackupListener .ERROR_AUTHENTICATION .equals (reason ))
170- logout ();
154+ if (BackupController .OnRestoreBackupListener .ERROR_AUTHENTICATION .equals (reason )) logout ();
171155 }
172156 });
173157 }
174158
175159 private void fetchBackups () {
176160 startProgress (getString (R .string .fetching_backups ));
177161 backupController .fetchBackups (dbClient , new BackupController .OnFetchBackupListListener () {
178- @ Override
179- public void onBackupsFetched (@ NonNull List <String > backupList ) {
162+ @ Override public void onBackupsFetched (@ NonNull List <String > backupList ) {
180163 if (isFinishing ()) return ;
181164
182165 stopProgress ();
183- ArrayAdapter <String > adapter = new ArrayAdapter <>(BackupActivity .this ,
184- android .R .layout .simple_list_item_1 , backupList );
185- listView .setAdapter (adapter );
166+ listView .setAdapter (new BackupAdapter (BackupActivity .this , backupList ));
186167 }
187168 });
188169 }
0 commit comments