From 60df46d48c0cd85796622133a91865d8056fde29 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Mon, 14 Jul 2014 13:43:54 +0200 Subject: [PATCH] =?UTF-8?q?Sprawdzanie=20loginu=20i=20has=C5=82a=20w=20Log?= =?UTF-8?q?in=20Activity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nerull7/mysqlbrowser/LoginFragment.java | 55 +++++++++++++----- .../info/nerull7/mysqlbrowser/Static.java | 16 +++++ .../mysqlbrowser/db/DatabaseConnector.java | 13 +++++ .../res/drawable-hdpi/ic_action_warning.png | Bin 0 -> 850 bytes .../res/drawable-mdpi/ic_action_warning.png | Bin 0 -> 543 bytes app/src/main/res/values/strings.xml | 3 + 6 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/info/nerull7/mysqlbrowser/Static.java create mode 100644 app/src/main/res/drawable-hdpi/ic_action_warning.png create mode 100644 app/src/main/res/drawable-mdpi/ic_action_warning.png diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java index 4cb58b4..4f67105 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java @@ -3,23 +3,28 @@ package info.nerull7.mysqlbrowser; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; +import android.app.AlertDialog; import android.app.Fragment; +import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; +import info.nerull7.mysqlbrowser.db.DatabaseConnector; + /** * Created by nerull7 on 07.07.14. */ public class LoginFragment extends Fragment implements View.OnClickListener { - EditText uri; - EditText login; - EditText password; // TODO: Mega super epic security (RSA/AES maybe?) + EditText urlTextbox; + EditText loginTextbox; + EditText passwordTextbox; // TODO: Mega super epic security (RSA/AES maybe?) public LoginFragment(){ @@ -31,24 +36,42 @@ public class LoginFragment extends Fragment implements View.OnClickListener { View rootView = inflater.inflate(R.layout.fragment_login, container, false); rootView.findViewById(R.id.buttonLogin).setOnClickListener(this); - this.uri = (EditText) rootView.findViewById(R.id.editURL); - this.login = (EditText) rootView.findViewById(R.id.editLogin); - this.password = (EditText) rootView.findViewById(R.id.editPassowrd); + this.urlTextbox = (EditText) rootView.findViewById(R.id.editURL); + this.loginTextbox = (EditText) rootView.findViewById(R.id.editLogin); + this.passwordTextbox = (EditText) rootView.findViewById(R.id.editPassowrd); return rootView; } @Override public void onClick(View view) { -// DatabaseFragment databaseFragment = DatabaseFragment.newInstance(login.getText().toString(), -// password.getText().toString(), -// uri.getText().toString()); -// -// getFragmentManager().beginTransaction() -// .add(R.id.container, databaseFragment) -// .remove(this) -// .commit(); - Intent intent = new Intent(getActivity(), DatabaseActivity.class); - startActivity(intent); + checkLogin(); + } + + private void checkLogin(){ + String login, password, url; + 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); + Intent intent = new Intent(getActivity(), DatabaseActivity.class); + startActivity(intent); + } + else { + final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage(DatabaseConnector.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(); + } } } diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/Static.java b/app/src/main/java/info/nerull7/mysqlbrowser/Static.java new file mode 100644 index 0000000..fd10211 --- /dev/null +++ b/app/src/main/java/info/nerull7/mysqlbrowser/Static.java @@ -0,0 +1,16 @@ +package info.nerull7.mysqlbrowser; + +import info.nerull7.mysqlbrowser.db.DatabaseConnector; + +/** + * Created by nerull7 on 14.07.14. + */ +public class Static { + public static DatabaseConnector databaseConnector = null; + + public static boolean isDatabaseConnectorActive(){ + if (databaseConnector==null) + return false; + return true; + } +} 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 73016e6..0193679 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java @@ -15,12 +15,25 @@ public class DatabaseConnector { 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==null) + errorMsg = "No Password"; + else + errorMsg = "I don't know"; + return false; + } + public void setDatabaseInUse(String database){ this.database = database; } diff --git a/app/src/main/res/drawable-hdpi/ic_action_warning.png b/app/src/main/res/drawable-hdpi/ic_action_warning.png new file mode 100644 index 0000000000000000000000000000000000000000..47cdc391ae460fe85551e4826e48268d2ea41a86 GIT binary patch literal 850 zcmV-Y1FigtP)k`gNx$U-Da zi9)_V|G(=U-8<%)=X35mQ}3zMyze~EoO6D2<~eho>F#Q{bT>Tyt`0!EGgx&7X0`wy zR|Q%nzz_w!trhq&9e-2-Q6<1)1-zma^c5X%HVI&?g54n<-3t1njz^^LQ$tjhfi((r zelFO%`hTGb0FxEuR%!m`{MNbS(w8YAQfB~r8>KT0K|ay>(^6oPNNRw2ifXMTvhy0h zmn8avG{@K-ri*t<$6JiN)%aoQw-{&HwJ9^OOh%VF26bKYt~t&vot6qIuJ!2S{d_6qb#uY4gwGq6F9W|uhg z1;Erp>6w85m?b9wl);ApuwDRoyND`ThKx&17LH`*EO=>D=}p> z?~A+7S3N!k{3m4qJoh~RA(9dR|EvSngEPQ1&7|_!9x)SKY5@8qD$=vO!=eD`*|$ik z{dE%F2`8l7oPSaTz}uF$ZXJcUGjC}lz(|eIZStL`j>2~&y4BBFaQO_-Y0`1lS?E;h zSbL=}06jis)3i;j3l!T=$|`$@egNzBe@XJP)o2;;2q$L=M`|1RD??gl+PHbF@oK)UIt2x zc(@2?fxRyx!Z!P-;^@8AiMl^=taa8jCBN2#J6KNG3p) zL3Yl1Q|}EhHyQ8mSucXmI1v&7Z4mT?kk|w$mtAn2MnEafGoZv#z$<>U;3Z0gEd#wc zwnjKhGN4>fz>bT6YMjP_s)4X!D?-ml)xZ+C3nPikzz7a?ao;b&yK8J$lL%&jq8tf$ zhd0o^nF9Q6mOz7(NuYi63ozR(Cw75TpndZMM73E0J|~mk_RSLz*Je3I5IFs`Z?>yg hz?078UqIe7@D1{TPa(|Y!qWf%002ovPDHLkV1o92=f3~| literal 0 HcmV?d00001 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index da3499a..6831380 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,5 +10,8 @@ MainActivity DatabaseActivity Hello world! + Wrong login/password + OK + Error