Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit a029ff6

Browse files
author
Evgenii Kanivets
committed
#91[1h]. Show ProgressDialog while importing. Update gradle version to 2.1.2.
1 parent abadbd9 commit a029ff6

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/base/BaseActivity.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.blogspot.e_kanivets.moneytracker.activity.base;
22

3+
import android.app.ProgressDialog;
34
import android.os.Bundle;
45
import android.support.annotation.LayoutRes;
56
import android.support.annotation.Nullable;
@@ -25,6 +26,7 @@ public abstract class BaseActivity extends AppCompatActivity {
2526
private static final String TAG = "BaseActivity";
2627

2728
private Toolbar toolbar;
29+
protected ProgressDialog progressDialog;
2830

2931
@Override
3032
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -64,4 +66,19 @@ protected void showToast(String message) {
6466
protected void showToast(@StringRes int messageId) {
6567
Toast.makeText(BaseActivity.this, messageId, Toast.LENGTH_SHORT).show();
6668
}
67-
}
69+
70+
public void startProgress() {
71+
if (getProgressBar() == null) return;
72+
getProgressBar().show();
73+
}
74+
75+
public void stopProgress() {
76+
if (getProgressBar() == null) return;
77+
getProgressBar().dismiss();
78+
}
79+
80+
private ProgressDialog getProgressBar() {
81+
if (progressDialog == null) progressDialog = new ProgressDialog(this);
82+
return progressDialog;
83+
}
84+
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/external/ImportActivity.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.blogspot.e_kanivets.moneytracker.activity.external;
22

3+
import android.os.AsyncTask;
34
import android.support.v7.app.AlertDialog;
45
import android.view.Menu;
56
import android.view.MenuItem;
@@ -60,11 +61,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
6061

6162
@OnClick(R.id.btn_import)
6263
public void importRecords() {
63-
String data = etImportData.getText().toString().trim();
64-
List<Record> recordList = importController.importRecordsFromCsv(data);
65-
showToast(getString(R.string.records_imported, recordList.size()));
64+
final String data = etImportData.getText().toString().trim();
6665

67-
setResult(RESULT_OK);
68-
finish();
66+
AsyncTask<Void, Void, Integer> importTask = new AsyncTask<Void, Void, Integer>() {
67+
@Override
68+
protected void onPreExecute() {
69+
super.onPreExecute();
70+
startProgress();
71+
}
72+
73+
@Override
74+
protected Integer doInBackground(Void... params) {
75+
List<Record> recordList = importController.importRecordsFromCsv(data);
76+
return recordList.size();
77+
}
78+
79+
@Override
80+
protected void onPostExecute(Integer recordCount) {
81+
super.onPostExecute(recordCount);
82+
stopProgress();
83+
showToast(getString(R.string.records_imported, recordCount));
84+
setResult(RESULT_OK);
85+
finish();
86+
}
87+
};
88+
importTask.execute();
6989
}
7090
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
jcenter()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:2.1.0'
6+
classpath 'com.android.tools.build:gradle:2.1.2'
77
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
88
}
99
}
@@ -14,4 +14,4 @@ allprojects {
1414
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
1515
maven { url "https://jitpack.io" }
1616
}
17-
}
17+
}

0 commit comments

Comments
 (0)