diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 55fc68d..cf1aba4 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -30,4 +30,6 @@
+
+
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java
index 28cacfc..17e1c45 100644
--- a/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java
@@ -10,7 +10,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
-import info.nerull7.mysqlbrowser.db.DatabaseConnector;
+import info.nerull7.mysqlbrowser.db.FakeDatabaseConnector;
+import info.nerull7.mysqlbrowser.db.RealDatabaseConnector;
/**
* Created by nerull7 on 07.07.14.
@@ -47,14 +48,14 @@ public class LoginFragment extends Fragment implements View.OnClickListener {
login = loginTextbox.getText().toString();
password = passwordTextbox.getText().toString();
url = urlTextbox.getText().toString();
- if(DatabaseConnector.checkLogin(login, password, url)) {
- Static.databaseConnector = new DatabaseConnector(login, password, url);
+ if(RealDatabaseConnector.checkLogin(login, password, url)) {
+ Static.databaseConnector = new FakeDatabaseConnector(login, password, url);
Intent intent = new Intent(getActivity(), DatabaseActivity.class);
startActivity(intent);
}
else {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setMessage(DatabaseConnector.errorMsg);
+ builder.setMessage(RealDatabaseConnector.errorMsg);
builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java b/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java
index 14eb7bb..584807f 100644
--- a/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java
@@ -1,91 +1,22 @@
package info.nerull7.mysqlbrowser.db;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
/**
- * Created by nerull7 on 07.07.14.
+ * Created by nerull7 on 17.07.14.
*/
-public class DatabaseConnector {
- private String login;
- private String password;
- private String url;
-
- private String database;
- private String table;
-
- public static String errorMsg;
-
- public DatabaseConnector(String login, String password, String url){
- this.login = login;
- this.password = password;
- this.url = url;
- }
-
- // TODO Real checking
- public static boolean checkLogin(String login, String password, String url){
-// if (login.compareTo("nerull7")==0)
- return true;
-// if(password.compareTo("")==0)
-// errorMsg = "No Password";
-// else
-// errorMsg = "I don't know";
-// return false;
- }
-
- public void setDatabaseInUse(String database){
- this.database = database;
- }
+public interface DatabaseConnector {
+ void setDatabaseInUse(String database);
// TODO Real connection
- public List getDatabases(){
- List stringList = new ArrayList();
- stringList.add("Wordpress");
- stringList.add("DB1");
- stringList.add("owncloud");
- Collections.sort(stringList);
- return stringList;
- }
+ List getDatabases();
// TODO Real getTables
- public List getTables(){
- if(database==null) return null; // if database is not chosen return null
-
- List stringList = new ArrayList();
- stringList.add(database + ".Table1");
- stringList.add(database + ".Table2");
- stringList.add(database + ".Table3");
- return stringList;
- }
+ List getTables();
// TODO Real getFields
- public List getFields(String table){
- if(database==null) return null; // if database is not chosen return null
-
- List stringList = new ArrayList();
- stringList.add("Field 1");
- stringList.add("Field 2");
- stringList.add("Field 3");
- stringList.add("Field 4");
- stringList.add("Field 5");
- return stringList;
- }
+ List getFields(String table);
// TODO Real getRows
- public List> getRows(int count){
- if(database==null) return null; // if database is not chosen return null
- List> stringListList = new ArrayList>();
-
- for(int i=0;i stringList = new ArrayList();
- stringList.add("Data 1"+i);
- stringList.add("Data 2"+i);
- stringList.add("Data 3"+i);
- stringList.add("Data 4"+i);
- stringList.add("Field aaa aaaaaaaa aaaaaa aaaaa4"+i);
- stringListList.add(stringList);
- }
- return stringListList;
- }
+ List> getRows(int count);
}
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/db/FakeDatabaseConnector.java b/app/src/main/java/info/nerull7/mysqlbrowser/db/FakeDatabaseConnector.java
new file mode 100644
index 0000000..1b114a1
--- /dev/null
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/db/FakeDatabaseConnector.java
@@ -0,0 +1,96 @@
+package info.nerull7.mysqlbrowser.db;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created by nerull7 on 07.07.14.
+ */
+public class FakeDatabaseConnector implements DatabaseConnector {
+ private String login;
+ private String password;
+ private String url;
+
+ private String database;
+ private String table;
+
+ public static String errorMsg;
+
+ public FakeDatabaseConnector(String login, String password, String url){
+ this.login = login;
+ this.password = password;
+ this.url = url;
+ }
+
+ // TODO Real checking
+ public static boolean checkLogin(String login, String password, String url){
+// if (login.compareTo("nerull7")==0)
+ return true;
+// if(password.compareTo("")==0)
+// errorMsg = "No Password";
+// else
+// errorMsg = "I don't know";
+// return false;
+ }
+
+ @Override
+ public void setDatabaseInUse(String database){
+ this.database = database;
+ }
+
+ // TODO Real connection
+ @Override
+ public List getDatabases(){
+ List stringList = new ArrayList();
+ stringList.add("Wordpress");
+ stringList.add("DB1");
+ stringList.add("owncloud");
+ Collections.sort(stringList);
+ return stringList;
+ }
+
+ // TODO Real getTables
+ @Override
+ public List getTables(){
+ if(database==null) return null; // if database is not chosen return null
+
+ List stringList = new ArrayList();
+ stringList.add(database + ".Table1");
+ stringList.add(database + ".Table2");
+ stringList.add(database + ".Table3");
+ return stringList;
+ }
+
+ // TODO Real getFields
+ @Override
+ public List getFields(String table){
+ if(database==null) return null; // if database is not chosen return null
+
+ List stringList = new ArrayList();
+ stringList.add("Field 1");
+ stringList.add("Field 2");
+ stringList.add("Field 3");
+ stringList.add("Field 4");
+ stringList.add("Field 5");
+ return stringList;
+ }
+
+ // TODO Real getRows
+ @Override
+ public List> getRows(int count){
+ if(database==null) return null; // if database is not chosen return null
+ List> stringListList = new ArrayList>();
+
+ for(int i=0;i stringList = new ArrayList();
+ stringList.add("Data 1"+i);
+ stringList.add("Data 2"+i);
+ stringList.add("Data 3"+i);
+ stringList.add("Data 4"+i);
+ stringList.add("Field aaa aaaaaaaa aaaaaa aaaaa4"+i);
+ stringListList.add(stringList);
+ }
+ return stringListList;
+ }
+}
diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/db/RealDatabaseConnector.java b/app/src/main/java/info/nerull7/mysqlbrowser/db/RealDatabaseConnector.java
new file mode 100644
index 0000000..8fb412d
--- /dev/null
+++ b/app/src/main/java/info/nerull7/mysqlbrowser/db/RealDatabaseConnector.java
@@ -0,0 +1,176 @@
+package info.nerull7.mysqlbrowser.db;
+
+import android.os.StrictMode;
+import android.util.Log;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created by nerull7 on 07.07.14.
+ */
+public class RealDatabaseConnector implements DatabaseConnector {
+ private String login;
+ private String password;
+ private String url;
+
+ private String database;
+ private String table;
+
+ public static String errorMsg;
+
+ public RealDatabaseConnector(String login, String password, String url){
+ this.login = login;
+ this.password = password;
+ this.url = url;
+ }
+
+ private static void disableStrictMode(){ // TODO THIS NEEDS TO NOT BE USED, WE CAN GET
+ StrictMode.ThreadPolicy policy = new StrictMode.
+ ThreadPolicy.Builder().permitAll().build();
+ StrictMode.setThreadPolicy(policy);
+ }
+
+ private static String httpRequest(String urlRequest) throws IOException {
+ disableStrictMode(); // FIXME
+ URL url = new URL(urlRequest);
+ HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+ InputStream inputStream = null;
+ String response;
+ if(urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ try {
+ inputStream = new BufferedInputStream(urlConnection.getInputStream());
+ response = readStream(inputStream);
+ } finally {
+ urlConnection.disconnect();
+ }
+ return response;
+ }
+ else {
+// try {
+// inputStream = new BufferedInputStream(urlConnection.getErrorStream());
+// errorMsg = readStream(inputStream);
+// } finally {
+// urlConnection.disconnect();
+// }
+// return null;
+ errorMsg = "ERROR: "+urlConnection.getResponseCode();
+ return null;
+ }
+ }
+
+ private static String readStream(InputStream in) {
+ String streamOutput = "";
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(in));
+ String line = "";
+ while ((line = reader.readLine()) != null) {
+ streamOutput += line;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return streamOutput;
+ }
+
+ private static String actionUrlBuilder(String login, String password, String url, String action){
+ String urlBuilder = url;
+ urlBuilder += "?u="+login;
+ urlBuilder += "&p="+password;
+ urlBuilder += "&a="+action;
+ Log.d("URLBuilder", urlBuilder);
+ return urlBuilder;
+ }
+
+ // TODO Real checking
+ public static boolean checkLogin(String login, String password, String url){
+ errorMsg = null;
+ try {
+ String response = httpRequest(actionUrlBuilder(login,password,url,"login"));
+ if(response==null)
+ return false;
+ if(response.compareTo("OK")==0){
+ return true;
+ }
+ else {
+ errorMsg = response;
+ return false;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ public void setDatabaseInUse(String database){
+ this.database = database;
+ }
+
+ // TODO Real connection
+ public List getDatabases(){
+ List stringList = new ArrayList();
+ stringList.add("Wordpress");
+ stringList.add("DB1");
+ stringList.add("owncloud");
+ Collections.sort(stringList);
+ return stringList;
+ }
+
+ // TODO Real getTables
+ public List getTables(){
+ if(database==null) return null; // if database is not chosen return null
+
+ List stringList = new ArrayList();
+ stringList.add(database + ".Table1");
+ stringList.add(database + ".Table2");
+ stringList.add(database + ".Table3");
+ return stringList;
+ }
+
+ // TODO Real getFields
+ public List getFields(String table){
+ if(database==null) return null; // if database is not chosen return null
+
+ List stringList = new ArrayList();
+ stringList.add("Field 1");
+ stringList.add("Field 2");
+ stringList.add("Field 3");
+ stringList.add("Field 4");
+ stringList.add("Field 5");
+ return stringList;
+ }
+
+ // TODO Real getRows
+ public List> getRows(int count){
+ if(database==null) return null; // if database is not chosen return null
+ List> stringListList = new ArrayList>();
+
+ for(int i=0;i stringList = new ArrayList();
+ stringList.add("Data 1"+i);
+ stringList.add("Data 2"+i);
+ stringList.add("Data 3"+i);
+ stringList.add("Data 4"+i);
+ stringList.add("Field aaa aaaaaaaa aaaaaa aaaaa4"+i);
+ stringListList.add(stringList);
+ }
+ return stringListList;
+ }
+}