diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 09f4cb8..5829f73 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -37,5 +37,6 @@
+
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java
index d1648d0..21d4671 100644
--- a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java
@@ -45,12 +45,16 @@ public class DatabaseFragment extends Fragment implements AdapterView.OnItemClic
@Override
public void onItemClick(AdapterView> adapterView, View view, int position, long id) {
- String chosenDatabase = (String) listAdapter.getItem(position);
- listAdapter.getItem(position);
- Intent intent = new Intent(getActivity(), TableActivity.class);
- intent.putExtra(Static.DATABASE_NAME_ARG,chosenDatabase);
- Static.asyncDatabaseConnector.setDatabaseInUse(chosenDatabase);
- startActivity(intent);
+ if(Static.isNetworkConnected(getActivity())) {
+ String chosenDatabase = (String) listAdapter.getItem(position);
+ listAdapter.getItem(position);
+ Intent intent = new Intent(getActivity(), TableActivity.class);
+ intent.putExtra(Static.DATABASE_NAME_ARG, chosenDatabase);
+ Static.asyncDatabaseConnector.setDatabaseInUse(chosenDatabase);
+ startActivity(intent);
+ } else {
+ Static.showErrorAlert(getResources().getString(R.string.no_connection), getActivity());
+ }
}
@Override
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java
index fc90c18..005821c 100644
--- a/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/EntriesFragment.java
@@ -139,21 +139,23 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()){
- case R.id.action_previous:
- page--;
- break;
- case R.id.action_next:
- page++;
- break;
+ if(Static.isNetworkConnected(getActivity())) {
+ switch (item.getItemId()) {
+ case R.id.action_previous:
+ page--;
+ break;
+ case R.id.action_next:
+ page++;
+ break;
+ }
+ changeMenus(page);
+ entriesTable.removeAllViews(); // clean table
+
+ setLoading(true);
+ Static.asyncDatabaseConnector.getRows(tableName, entriesLimit, page); // get new entries
+ } else {
+ Static.showErrorAlert(getResources().getString(R.string.no_connection), getActivity());
}
- changeMenus(page);
- entriesTable.removeAllViews(); // clean table
-
- setLoading(true);
- Static.asyncDatabaseConnector.getRows(tableName, entriesLimit, page); // get new entries
-
-
return super.onOptionsItemSelected(item);
}
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java
index c17bddf..41cb054 100644
--- a/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java
@@ -85,9 +85,16 @@ public class LoginFragment extends Fragment implements View.OnClickListener, Asy
login = loginTextbox.getText().toString();
password = passwordTextbox.getText().toString();
url = urlTextbox.getText().toString();
- asyncDatabaseConnector = new AsyncDatabaseConnector(login, password, url);
- asyncDatabaseConnector.setBooleanReturnListener(this);
- asyncDatabaseConnector.checkLogin();
+
+ if(Static.isNetworkConnected(getActivity())) {
+ asyncDatabaseConnector = new AsyncDatabaseConnector(login, password, url);
+ asyncDatabaseConnector.setBooleanReturnListener(this);
+ asyncDatabaseConnector.checkLogin();
+ } else {
+ Static.showErrorAlert(getResources().getString(R.string.no_connection), getActivity());
+ loginButton.setEnabled(true); // Now we can click button again
+ progressBar.setVisibility(View.INVISIBLE);
+ }
}
@Override
@@ -98,21 +105,11 @@ public class LoginFragment extends Fragment implements View.OnClickListener, Asy
startActivity(intent);
}
else {
- final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setMessage(Static.asyncDatabaseConnector.errorMsg);
- builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- // Nothing to do here
- // Cleaning inputs is stupid
- }
- });
- builder.setTitle(R.string.error);
- builder.setIcon(R.drawable.ic_action_warning);
- builder.create();
- builder.show();
+ Static.showErrorAlert(Static.asyncDatabaseConnector.errorMsg, getActivity());
}
loginButton.setEnabled(true); // Now we can click button again
progressBar.setVisibility(View.INVISIBLE);
}
+
+
}
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/Static.java b/app/src/main/java/info/nerull7/mysqlbrowser/Static.java
index 055f1f7..1013bec 100644
--- a/app/src/main/java/info/nerull7/mysqlbrowser/Static.java
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/Static.java
@@ -1,7 +1,13 @@
package info.nerull7.mysqlbrowser;
+import android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+import java.net.NetworkInterface;
import info.nerull7.mysqlbrowser.db.AsyncDatabaseConnector;
@@ -18,4 +24,29 @@ public class Static {
Intent intent = new Intent(context, SettingsActivity.class);
context.startActivity(intent);
}
+
+ public static boolean isNetworkConnected(Context context){
+ ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
+ if(networkInfo!=null && networkInfo.isConnected()){
+ return true;
+ } else
+ return false;
+ }
+
+ public static void showErrorAlert(String errorMessage, Context context){
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setMessage(errorMessage);
+ builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ // Nothing to do here
+ // Cleaning inputs is stupid
+ }
+ });
+ builder.setTitle(R.string.error);
+ builder.setIcon(R.drawable.ic_action_warning);
+ builder.create();
+ builder.show();
+ }
}
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java
index 812f260..91d63f7 100644
--- a/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/TableFragment.java
@@ -45,12 +45,17 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi
@Override
public void onItemClick(AdapterView> adapterView, View view, int position, long id) {
- String chosenTable = (String) listAdapter.getItem(position);
- listAdapter.getItem(position);
- Intent intent = new Intent(getActivity(), EntriesActivity.class);
- intent.putExtra(Static.DATABASE_NAME_ARG,databaseName);
- intent.putExtra(Static.TABLE_NAME_ARG,chosenTable);
- startActivity(intent);
+ if(Static.isNetworkConnected(getActivity())) {
+ String chosenTable = (String) listAdapter.getItem(position);
+ listAdapter.getItem(position);
+ Intent intent = new Intent(getActivity(), EntriesActivity.class);
+ intent.putExtra(Static.DATABASE_NAME_ARG,databaseName);
+ intent.putExtra(Static.TABLE_NAME_ARG,chosenTable);
+ startActivity(intent);
+ } else {
+ Static.showErrorAlert(getResources().getString(R.string.no_connection), getActivity());
+ }
+
}
@Override
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ff22c47..6d1f5be 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -30,5 +30,6 @@
Login credentials
Save credentials
Connector URL
+ No Internet Connection