Removed arbitrary strings
now they are in public static final form some general fixes
This commit is contained in:
parent
70ad81014d
commit
b928ca6fc6
10 changed files with 43 additions and 28 deletions
|
@ -21,6 +21,8 @@ import info.nerull7.mysqlbrowser.db.AsyncDatabaseConnector;
|
|||
|
||||
/**
|
||||
* Created by nerull7 on 14.07.14.
|
||||
*
|
||||
* Fragment for showing list of Available Databases for user
|
||||
*/
|
||||
public class DatabaseFragment extends Fragment implements AdapterView.OnItemClickListener, AsyncDatabaseConnector.ListReturnListener {
|
||||
private ListView databasesListView;
|
||||
|
|
|
@ -15,8 +15,9 @@ public class EntriesActivity extends Activity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_entries);
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
bundle.putInt("Page", 0);
|
||||
String titleName = bundle.getString("DatabaseName")+"->"+bundle.getString("TableName");
|
||||
bundle.putInt(Static.PAGE_ARG, 0);
|
||||
// String titleName = bundle.getString(Static.DATABASE_NAME_ARG)+"->"+bundle.getString(Static.TABLE_NAME_ARG);
|
||||
String titleName = bundle.getString(Static.TABLE_NAME_ARG);
|
||||
setTitle(titleName);
|
||||
|
||||
EntriesFragment entriesFragment = new EntriesFragment();
|
||||
|
@ -29,12 +30,11 @@ public class EntriesActivity extends Activity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
public boolean onOptionsItemSelected(MenuItem item) { // TODO Implement pages
|
||||
switch (item.getItemId()){
|
||||
case R.id.action_previous:
|
||||
case R.id.action_next:
|
||||
// item.setEnabled(!item.isEnabled());
|
||||
// item.setVisible(!item.isVisible());
|
||||
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -42,14 +42,14 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector.
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_entries, container, false);
|
||||
databaseName = getArguments().getString("DatabaseName");
|
||||
tableName = getArguments().getString("TableName");
|
||||
databaseName = getArguments().getString(Static.DATABASE_NAME_ARG);
|
||||
tableName = getArguments().getString(Static.TABLE_NAME_ARG);
|
||||
entriesTable = (TableLayout) rootView.findViewById(R.id.entriesTable);
|
||||
entriesScrollView = (ScrollView) rootView.findViewById(R.id.entriesScrollView);
|
||||
headerFrame = (FrameLayout) rootView.findViewById(R.id.headerFrame);
|
||||
entriesLimit = getActivity().getSharedPreferences(SettingsFragment.PREFERENCE_FILE, Context.MODE_PRIVATE).getInt(SettingsFragment.ENTRIES_PAGE_LIMIT, SettingsFragment.ENTRIES_PAGE_LIMIT_DEF);
|
||||
this.rootView = (RelativeLayout) rootView;
|
||||
page = getArguments().getInt("Page");
|
||||
page = getArguments().getInt(Static.PAGE_ARG);
|
||||
progressBar = (ProgressBar) rootView.findViewById(R.id.loginProgressBar);
|
||||
// setupActionBar();
|
||||
|
||||
|
|
|
@ -43,10 +43,10 @@ public class LoginFragment extends Fragment implements View.OnClickListener, Asy
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
checkAsycnLogin();
|
||||
checkLogin();
|
||||
}
|
||||
|
||||
private void checkAsycnLogin(){
|
||||
private void checkLogin(){
|
||||
String login, password, url;
|
||||
login = loginTextbox.getText().toString();
|
||||
password = passwordTextbox.getText().toString();
|
||||
|
|
|
@ -7,6 +7,8 @@ import android.preference.PreferenceActivity;
|
|||
|
||||
/**
|
||||
* Created by nerull7 on 18.07.14.
|
||||
*
|
||||
* Simple activity for SettingsFragment
|
||||
*/
|
||||
public class SettingsActivity extends PreferenceActivity {
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ public class SettingsFragment extends PreferenceFragment implements NumberPicker
|
|||
public static final int ENTRIES_MIN_PAGE = 20;
|
||||
public static final int ENTRIES_MAX_PAGE = 100;
|
||||
|
||||
private Activity parent;
|
||||
private SharedPreferences preferences;
|
||||
private Preference mEntriesLimit;
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ import info.nerull7.mysqlbrowser.db.AsyncDatabaseConnector;
|
|||
* Created by nerull7 on 14.07.14.
|
||||
*/
|
||||
public class Static {
|
||||
public static final String DATABASE_NAME_ARG = "DatabaseName";
|
||||
public static final String TABLE_NAME_ARG = "TableName";
|
||||
public static final String PAGE_ARG = "Page";
|
||||
|
||||
public static AsyncDatabaseConnector asyncDatabaseConnector = null;
|
||||
|
||||
public static void startSettings(Context context){
|
||||
|
|
|
@ -11,7 +11,7 @@ public class TableActivity extends Activity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_table);
|
||||
setTitle(getIntent().getStringExtra("DatabaseName"));
|
||||
setTitle(getIntent().getStringExtra(Static.DATABASE_NAME_ARG));
|
||||
|
||||
TableFragment tableFragment = new TableFragment();
|
||||
tableFragment.setArguments(getIntent().getExtras());
|
||||
|
|
|
@ -34,7 +34,7 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_table, container, false);
|
||||
databaseName = getArguments().getString("DatabaseName");
|
||||
databaseName = getArguments().getString(Static.DATABASE_NAME_ARG);
|
||||
tablesList = (ListView) rootView.findViewById(R.id.tableList);
|
||||
this.rootView = (RelativeLayout) rootView;
|
||||
progressBar = (ProgressBar) rootView.findViewById(R.id.loginProgressBar);
|
||||
|
@ -45,11 +45,11 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi
|
|||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
||||
String choosenTable = (String) listAdapter.getItem(position);
|
||||
String chosenTable = (String) listAdapter.getItem(position);
|
||||
listAdapter.getItem(position);
|
||||
Intent intent = new Intent(getActivity(), EntriesActivity.class);
|
||||
intent.putExtra("DatabaseName",databaseName);
|
||||
intent.putExtra("TableName",choosenTable);
|
||||
intent.putExtra(Static.DATABASE_NAME_ARG,databaseName);
|
||||
intent.putExtra(Static.TABLE_NAME_ARG,chosenTable);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,17 @@ import java.util.List;
|
|||
* Created by nerull7 on 07.07.14.
|
||||
*/
|
||||
public class AsyncDatabaseConnector {
|
||||
public static final String ACTION_LOGIN = "login";
|
||||
public static final String ACTION_DATABASE_LIST = "dblist";
|
||||
public static final String ACTION_TABLE_LIST = "tablelist";
|
||||
public static final String ACTION_FIELD_LIST = "fieldlist";
|
||||
public static final String ACTION_DATA_MATRIX = "getrows";
|
||||
|
||||
private String login;
|
||||
private String password;
|
||||
private String url;
|
||||
|
||||
private String database;
|
||||
private String table;
|
||||
|
||||
private BooleanReturnListener booleanReturnListener;
|
||||
private StringReturnListener stringReturnListener;
|
||||
|
@ -44,12 +49,12 @@ public class AsyncDatabaseConnector {
|
|||
matrixReturnListener=null;
|
||||
}
|
||||
|
||||
private String actionUrlBuilder(String action){
|
||||
private String actionUrlBuilder(String action){ // TODO Better UrlBuilder this is shit only for use
|
||||
String urlBuilder = url;
|
||||
urlBuilder += "?u="+login;
|
||||
urlBuilder += "&p="+password;
|
||||
urlBuilder += "&a="+action;
|
||||
Log.d("Async URLBuilder", urlBuilder);
|
||||
// Log.d("URLBuilder", urlBuilder);
|
||||
return urlBuilder;
|
||||
}
|
||||
|
||||
|
@ -129,25 +134,25 @@ public class AsyncDatabaseConnector {
|
|||
booleanReturnListener.onBooleanReturn(listenerData);
|
||||
}
|
||||
});
|
||||
downloader.execute(actionUrlBuilder("login"));
|
||||
downloader.execute(actionUrlBuilder(ACTION_LOGIN));
|
||||
return false;
|
||||
}
|
||||
|
||||
public void getDatabases(){
|
||||
getList(actionUrlBuilder("dblist")); // TODO Redefine as public static final
|
||||
getList(actionUrlBuilder(ACTION_DATABASE_LIST));
|
||||
}
|
||||
|
||||
public void getTables(){
|
||||
getList(actionUrlBuilder("tablelist")+"&d="+database); // TODO Redefine as public static final
|
||||
getList(actionUrlBuilder(ACTION_TABLE_LIST)+"&d="+database);
|
||||
}
|
||||
|
||||
public void getFields(String table){
|
||||
getList(actionUrlBuilder("fieldlist")+"&d="+database+"&t="+table); // TODO Redefine as public static final
|
||||
getList(actionUrlBuilder(ACTION_FIELD_LIST)+"&d="+database+"&t="+table);
|
||||
}
|
||||
|
||||
public void getRows(String table, int count, int page){
|
||||
int limitStart = page * count;
|
||||
getMatrix(actionUrlBuilder("getrows")+"&d="+database+"&t="+table+"&s="+limitStart+"&l="+count); //FIXME
|
||||
getMatrix(actionUrlBuilder(ACTION_DATA_MATRIX)+"&d="+database+"&t="+table+"&s="+limitStart+"&l="+count);
|
||||
}
|
||||
|
||||
public void setBooleanReturnListener(BooleanReturnListener booleanReturnListener){
|
||||
|
@ -186,6 +191,10 @@ public class AsyncDatabaseConnector {
|
|||
private OnFinishedListener onFinishedListener;
|
||||
private String errorString;
|
||||
|
||||
public static final String CONNECTION_REQUEST_METHOD = "GET";
|
||||
public static final int CONNECTION_TIMEOUT = 15000;
|
||||
public static final int READ_TIMEOUT = 10000;
|
||||
|
||||
Downloader(OnFinishedListener onFinishedListener){
|
||||
this.onFinishedListener = onFinishedListener;
|
||||
errorString = null;
|
||||
|
@ -197,10 +206,9 @@ public class AsyncDatabaseConnector {
|
|||
String response;
|
||||
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); // TODO Handling no connection
|
||||
urlConnection.setReadTimeout(10000 /* miliseconds FIXME*/);
|
||||
urlConnection.setConnectTimeout(15000 /* miliseconds FIXME */);
|
||||
urlConnection.setRequestMethod("GET");
|
||||
urlConnection.setDoInput(true); // TODO what it does?
|
||||
urlConnection.setReadTimeout(READ_TIMEOUT);
|
||||
urlConnection.setConnectTimeout(CONNECTION_TIMEOUT);
|
||||
urlConnection.setRequestMethod(CONNECTION_REQUEST_METHOD);
|
||||
urlConnection.connect();
|
||||
|
||||
if(urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue