From 06118865df261b304038c316aa7067921a6d83ac Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Mon, 14 Jul 2014 10:31:41 +0200 Subject: [PATCH] Database Layout fixup --- app/src/main/AndroidManifest.xml | 10 +- .../mysqlbrowser/DatabaseActivity.java | 49 +++++++ .../mysqlbrowser/DatabaseConnector.java | 30 ---- .../mysqlbrowser/DatabaseFragment.java | 135 +----------------- .../nerull7/mysqlbrowser/LoginFragment.java | 19 +-- .../mysqlbrowser/db/DatabaseConnector.java | 72 ++++++++++ .../mysqlbrowser/dummy/DummyContent.java | 55 ------- app/src/main/res/layout/activity_database.xml | 7 + app/src/main/res/layout/fragment_database.xml | 16 +++ .../res/layout/fragment_database_grid.xml | 20 --- .../res/layout/fragment_database_list.xml | 19 --- app/src/main/res/menu/database.xml | 8 ++ app/src/main/res/values-large/refs.xml | 12 -- app/src/main/res/values-sw600dp/refs.xml | 12 -- app/src/main/res/values/refs.xml | 12 -- app/src/main/res/values/strings.xml | 2 + 16 files changed, 179 insertions(+), 299 deletions(-) create mode 100644 app/src/main/java/info/nerull7/mysqlbrowser/DatabaseActivity.java delete mode 100644 app/src/main/java/info/nerull7/mysqlbrowser/DatabaseConnector.java create mode 100644 app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java delete mode 100644 app/src/main/java/info/nerull7/mysqlbrowser/dummy/DummyContent.java create mode 100644 app/src/main/res/layout/activity_database.xml create mode 100644 app/src/main/res/layout/fragment_database.xml delete mode 100644 app/src/main/res/layout/fragment_database_grid.xml delete mode 100644 app/src/main/res/layout/fragment_database_list.xml create mode 100644 app/src/main/res/menu/database.xml delete mode 100644 app/src/main/res/values-large/refs.xml delete mode 100644 app/src/main/res/values-sw600dp/refs.xml delete mode 100644 app/src/main/res/values/refs.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5a9fbac..dd0c6b9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,11 +11,15 @@ android:name=".MainActivity" android:label="@string/app_name" > - - + + + - + + diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseActivity.java b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseActivity.java new file mode 100644 index 0000000..a83d655 --- /dev/null +++ b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseActivity.java @@ -0,0 +1,49 @@ +package info.nerull7.mysqlbrowser; + +import android.app.Activity; +import android.app.ActionBar; +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.os.Build; + +import info.nerull7.mysqlbrowser.R; + +public class DatabaseActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_database); + if (savedInstanceState == null) { + getFragmentManager().beginTransaction() + .add(R.id.container, new DatabaseFragment()) + .commit(); + } + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.database, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + if (id == R.id.action_settings) { + return true; + } + return super.onOptionsItemSelected(item); + } + +} diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseConnector.java b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseConnector.java deleted file mode 100644 index ee64870..0000000 --- a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseConnector.java +++ /dev/null @@ -1,30 +0,0 @@ -package info.nerull7.mysqlbrowser; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Created by nerull7 on 07.07.14. - */ -public class DatabaseConnector { - private String login; - private String password; - private String url; - - public DatabaseConnector(String login, String password, String url){ - this.login = login; - this.password = password; - this.url = url; - } - - // TODO Real connection - public List getDatabases(){ - List stringList = new ArrayList(); - stringList.add("Wordpress"); - stringList.add("DB1"); - stringList.add("owncloud"); - Collections.sort(stringList); - return stringList; - } -} diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java index e77da69..0c37b00 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/DatabaseFragment.java @@ -1,141 +1,20 @@ package info.nerull7.mysqlbrowser; -import android.animation.ValueAnimator; -import android.app.Activity; -import android.net.Uri; -import android.os.Bundle; import android.app.Fragment; +import android.os.Bundle; +import android.provider.ContactsContract; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewAnimationUtils; import android.view.ViewGroup; -import android.widget.AbsListView; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListAdapter; -import android.widget.TextView; - - -import info.nerull7.mysqlbrowser.dummy.DummyContent; /** - * A fragment representing a list of Items. - *

- * Large screen devices (such as tablets) are supported by replacing the ListView - * with a GridView. - *

- * Activities containing this fragment MUST implement the {@link Callbacks} - * interface. + * Created by nerull7 on 14.07.14. */ -public class DatabaseFragment extends Fragment implements AbsListView.OnItemClickListener { - private static final String ARG_LOGIN = "login"; - private static final String ARG_PASSWORD = "password"; - private static final String ARG_SERVER_URL = "serverUrl"; - - // Database info - private String serverUrl; - private String password; - private String login; - - private OnFragmentInteractionListener mListener; - - public static DatabaseFragment newInstance(String login, String password, String serverUrl) { - DatabaseFragment fragment = new DatabaseFragment(); - Bundle args = new Bundle(); - args.putString(ARG_LOGIN, login); - args.putString(ARG_PASSWORD, password); - args.putString(ARG_SERVER_URL, serverUrl); - - fragment.setArguments(args); - - return fragment; - } - - /** - * Mandatory empty constructor for the fragment manager to instantiate the - * fragment (e.g. upon screen orientation changes). - */ - public DatabaseFragment() { - } +public class DatabaseFragment extends Fragment { @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - if (getArguments() != null) { - login = getArguments().getString(ARG_LOGIN); - password = getArguments().getString(ARG_PASSWORD); - serverUrl = getArguments().getString(ARG_SERVER_URL); - } - - // TODO: Change Adapter to display your content + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ + //Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_database, container, false); } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_database, container, false); - - // Set the adapter - - // Set OnItemClickListener so we can be notified on item clicks - - return view; - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); -// try { -// mListener = (OnFragmentInteractionListener) activity; -// } catch (ClassCastException e) { -// throw new ClassCastException(activity.toString() -// + " must implement OnFragmentInteractionListener"); -// } - } - - @Override - public void onDetach() { - super.onDetach(); - mListener = null; - } - - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (null != mListener) { - // Notify the active callbacks interface (the activity, if the - // fragment is attached to one) that an item has been selected. - mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id); - } - } - - /** - * The default content for this Fragment has a TextView that is shown when - * the list is empty. If you would like to change the text, call this method - * to supply the text it should use. - */ - public void setEmptyText(CharSequence emptyText) { - View emptyView = mListView.getEmptyView(); - - if (emptyText instanceof TextView) { - ((TextView) emptyView).setText(emptyText); - } - } - - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - *

- * See the Android Training lesson Communicating with Other Fragments for more information. - */ - public interface OnFragmentInteractionListener { - // TODO: Update argument type and name - public void onFragmentInteraction(String id); - } - } diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java index 1d51cf1..509790f 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/LoginFragment.java @@ -4,6 +4,7 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.app.Fragment; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; @@ -40,13 +41,15 @@ public class LoginFragment extends Fragment implements View.OnClickListener { @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(); +// 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); } } diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java b/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java new file mode 100644 index 0000000..73016e6 --- /dev/null +++ b/app/src/main/java/info/nerull7/mysqlbrowser/db/DatabaseConnector.java @@ -0,0 +1,72 @@ +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 DatabaseConnector { + private String login; + private String password; + private String url; + + private String database; + private String table; + + public DatabaseConnector(String login, String password, String url){ + this.login = login; + this.password = password; + this.url = url; + } + + 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"); + return stringList; + } + + // TODO Real getRows + public List getRows(int count){ + if(database==null) return null; // if database is not chosen return null + + List stringList = new ArrayList(); + stringList.add("Data 1"); + stringList.add("Data 2"); + stringList.add("Data 3"); + stringList.add("Data 4"); + return stringList; + } +} diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/dummy/DummyContent.java b/app/src/main/java/info/nerull7/mysqlbrowser/dummy/DummyContent.java deleted file mode 100644 index 720f27c..0000000 --- a/app/src/main/java/info/nerull7/mysqlbrowser/dummy/DummyContent.java +++ /dev/null @@ -1,55 +0,0 @@ -package info.nerull7.mysqlbrowser.dummy; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Helper class for providing sample content for user interfaces created by - * Android template wizards. - *

- * TODO: Replace all uses of this class before publishing your app. - */ -public class DummyContent { - - /** - * An array of sample (dummy) items. - */ - public static List ITEMS = new ArrayList(); - - /** - * A map of sample (dummy) items, by ID. - */ - public static Map ITEM_MAP = new HashMap(); - - static { - // Add 3 sample items. - addItem(new DummyItem("1", "Item 1")); - addItem(new DummyItem("2", "Item 2")); - addItem(new DummyItem("3", "Item 3")); - } - - private static void addItem(DummyItem item) { - ITEMS.add(item); - ITEM_MAP.put(item.id, item); - } - - /** - * A dummy item representing a piece of content. - */ - public static class DummyItem { - public String id; - public String content; - - public DummyItem(String id, String content) { - this.id = id; - this.content = content; - } - - @Override - public String toString() { - return content; - } - } -} diff --git a/app/src/main/res/layout/activity_database.xml b/app/src/main/res/layout/activity_database.xml new file mode 100644 index 0000000..c4d324d --- /dev/null +++ b/app/src/main/res/layout/activity_database.xml @@ -0,0 +1,7 @@ + diff --git a/app/src/main/res/layout/fragment_database.xml b/app/src/main/res/layout/fragment_database.xml new file mode 100644 index 0000000..a673b26 --- /dev/null +++ b/app/src/main/res/layout/fragment_database.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/layout/fragment_database_grid.xml b/app/src/main/res/layout/fragment_database_grid.xml deleted file mode 100644 index eb15d94..0000000 --- a/app/src/main/res/layout/fragment_database_grid.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/layout/fragment_database_list.xml b/app/src/main/res/layout/fragment_database_list.xml deleted file mode 100644 index 7ed34a6..0000000 --- a/app/src/main/res/layout/fragment_database_list.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/menu/database.xml b/app/src/main/res/menu/database.xml new file mode 100644 index 0000000..79392ac --- /dev/null +++ b/app/src/main/res/menu/database.xml @@ -0,0 +1,8 @@ +

+ + diff --git a/app/src/main/res/values-large/refs.xml b/app/src/main/res/values-large/refs.xml deleted file mode 100644 index 1d0b95e..0000000 --- a/app/src/main/res/values-large/refs.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - @layout/fragment_database_grid - - \ No newline at end of file diff --git a/app/src/main/res/values-sw600dp/refs.xml b/app/src/main/res/values-sw600dp/refs.xml deleted file mode 100644 index 1d0b95e..0000000 --- a/app/src/main/res/values-sw600dp/refs.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - @layout/fragment_database_grid - - \ No newline at end of file diff --git a/app/src/main/res/values/refs.xml b/app/src/main/res/values/refs.xml deleted file mode 100644 index 1e7cad4..0000000 --- a/app/src/main/res/values/refs.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - @layout/fragment_database_list - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9062258..da3499a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,5 +8,7 @@ Username URL ex: https://example.com/c.php MainActivity + DatabaseActivity + Hello world!