Try to make UI not stuck - DO NOT MERGE

It doesn't work SHIT
This commit is contained in:
Przemek Grondek 2014-07-31 15:23:52 +02:00
parent 07667f69c7
commit 0304cc2590
5 changed files with 245 additions and 92 deletions

View file

@ -30,6 +30,8 @@ public class DatabaseFragment extends Fragment implements AdapterView.OnItemClic
private RelativeLayout rootView;
private ProgressBar progressBar;
private String chosenDatabase;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
//Inflate the layout for this fragment
@ -38,35 +40,48 @@ public class DatabaseFragment extends Fragment implements AdapterView.OnItemClic
this.rootView = (RelativeLayout) rootView;
progressBar = (ProgressBar) rootView.findViewById(R.id.loginProgressBar);
Static.asyncDatabaseConnector.setListReturnListener(this);
Static.asyncDatabaseConnector.getDatabases();
// Static.asyncDatabaseConnector.setListReturnListener(this);
// Static.asyncDatabaseConnector.getDatabases();
listAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, Static.databases);
databasesListView.setAdapter(listAdapter);
databasesListView.setOnItemClickListener(this);
progressBar.setVisibility(View.INVISIBLE);
return rootView;
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
String chosenDatabase = (String) listAdapter.getItem(position);
chosenDatabase = (String) listAdapter.getItem(position);
listAdapter.getItem(position);
Intent intent = new Intent(getActivity(), TableActivity.class);
intent.putExtra(Static.DATABASE_NAME_ARG,chosenDatabase);
progressBar.setVisibility(View.VISIBLE);
Static.asyncDatabaseConnector.setDatabaseInUse(chosenDatabase);
startActivity(intent);
Static.asyncDatabaseConnector.setListReturnListener(this);
Static.asyncDatabaseConnector.getTables();
}
@Override
public void onListReturn(List<String> databases) {
if(databases!= null) {
listAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, databases);
databasesListView.setAdapter(listAdapter);
databasesListView.setOnItemClickListener(this);
} else {
TextView errorMessage = new TextView(getActivity());
errorMessage.setText(R.string.error_no_databases);
errorMessage.setTypeface(null, Typeface.ITALIC);
errorMessage.setClickable(false);
rootView.addView(errorMessage);
rootView.removeView(databasesListView);
public void onListReturn(List<String> tables) {
// if(databases!= null) {
// listAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, databases);
// databasesListView.setAdapter(listAdapter);
// databasesListView.setOnItemClickListener(this);
// } else {
// TextView errorMessage = new TextView(getActivity());
// errorMessage.setText(R.string.error_no_databases);
// errorMessage.setTypeface(null, Typeface.ITALIC);
// errorMessage.setClickable(false);
// rootView.addView(errorMessage);
// rootView.removeView(databasesListView);
// }
// progressBar.setVisibility(View.INVISIBLE);
if(tables!=null) {
Static.tables = tables;
}
progressBar.setVisibility(View.INVISIBLE);
Intent intent = new Intent(getActivity(), TableActivity.class);
intent.putExtra(Static.DATABASE_NAME_ARG, chosenDatabase);
startActivity(intent);
}
}

View file

@ -62,11 +62,62 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector.
initArguments();
initViewItems(rootView);
Static.asyncDatabaseConnector.setIntegerReturnListener(this);
Static.asyncDatabaseConnector.setListReturnListener(this);
Static.asyncDatabaseConnector.setMatrixReturnListener(this);
Static.asyncDatabaseConnector.getFields(tableName);
Static.asyncDatabaseConnector.getEntriesCount(tableName);
// Static.asyncDatabaseConnector.setIntegerReturnListener(this);
// Static.asyncDatabaseConnector.setListReturnListener(this);
// Static.asyncDatabaseConnector.setMatrixReturnListener(this);
// Static.asyncDatabaseConnector.getFields(tableName);
// Static.asyncDatabaseConnector.getEntriesCount(tableName);
pageCount = Static.pageCount/entriesLimit;
if( Static.pageCount%entriesLimit > 0)
pageCount++;
if(pageCount>1)
setHasOptionsMenu(true);
// First we need header
headerRow = new TableRow(getActivity());
headerRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
for(int i =0;i<Static.header.size();i++){
TextView textView = new TextView(getActivity());
textView.setText(Static.header.get(i));
textView.setTypeface(null, Typeface.BOLD);
textView.setLayoutParams(layoutParams);
textView.setBackgroundResource(R.drawable.background_header);
textView.setPadding(HEADER_PADDING_LEFT, HEADER_PADDING_TOP, HEADER_PADDING_RIGHT, HEADER_PADDING_BOTTOM);
headerRow.addView(textView);
}
headerFrame.addView(headerRow);
// now data
if(Static.entries!=null) {
for (int i = 0; i < Static.entries.size(); i++) {
List<String> elements = Static.entries.get(i);
TableRow newRow = new TableRow(getActivity());
for (int j = 0; j < elements.size(); j++) { // elements.size can be the same as in header so maybe some one number or not
TextView textView = new TextView(getActivity());
textView.setText(elements.get(j));
textView.setLayoutParams(layoutParams);
textView.setPadding(ENTRIES_PADDING_LEFT, ENTRIES_PADDING_TOP, ENTRIES_PADDING_RIGHT, ENTRIES_PADDING_BOTTOM);
textView.setBackgroundResource(R.drawable.background_element);
newRow.addView(textView);
}
entriesTable.addView(newRow);
syncWidths();
fakeScroll();
}
} else {
TextView errorMessage = new TextView(getActivity());
errorMessage.setText(R.string.error_no_entries);
errorMessage.setTypeface(null, Typeface.ITALIC);
errorMessage.setClickable(false);
entriesScrollView.removeView(entriesTable);
headerFrame.setVisibility(View.VISIBLE);
entriesScrollView.addView(errorMessage);
}
setLoading(false);
return rootView;
}
@ -153,54 +204,54 @@ public class EntriesFragment extends Fragment implements AsyncDatabaseConnector.
@Override
public void onMatrixReturn(List<List<String>> rows) {
// Now we get Rows
if(rows!=null) {
for (int i = 0; i < rows.size(); i++) {
List<String> elements = rows.get(i);
TableRow newRow = new TableRow(getActivity());
for (int j = 0; j < elements.size(); j++) { // elements.size can be the same as in header so maybe some one number or not
TextView textView = new TextView(getActivity());
textView.setText(elements.get(j));
textView.setLayoutParams(layoutParams);
textView.setPadding(ENTRIES_PADDING_LEFT, ENTRIES_PADDING_TOP, ENTRIES_PADDING_RIGHT, ENTRIES_PADDING_BOTTOM);
textView.setBackgroundResource(R.drawable.background_element);
newRow.addView(textView);
}
entriesTable.addView(newRow);
syncWidths();
fakeScroll();
}
} else {
TextView errorMessage = new TextView(getActivity());
errorMessage.setText(R.string.error_no_entries);
errorMessage.setTypeface(null, Typeface.ITALIC);
errorMessage.setClickable(false);
entriesScrollView.removeView(entriesTable);
headerFrame.setVisibility(View.VISIBLE);
entriesScrollView.addView(errorMessage);
}
setLoading(false);
// // Now we get Rows
// if(rows!=null) {
// for (int i = 0; i < rows.size(); i++) {
// List<String> elements = rows.get(i);
// TableRow newRow = new TableRow(getActivity());
// for (int j = 0; j < elements.size(); j++) { // elements.size can be the same as in header so maybe some one number or not
// TextView textView = new TextView(getActivity());
// textView.setText(elements.get(j));
// textView.setLayoutParams(layoutParams);
// textView.setPadding(ENTRIES_PADDING_LEFT, ENTRIES_PADDING_TOP, ENTRIES_PADDING_RIGHT, ENTRIES_PADDING_BOTTOM);
// textView.setBackgroundResource(R.drawable.background_element);
// newRow.addView(textView);
// }
// entriesTable.addView(newRow);
//
// syncWidths();
// fakeScroll();
// }
// } else {
// TextView errorMessage = new TextView(getActivity());
// errorMessage.setText(R.string.error_no_entries);
// errorMessage.setTypeface(null, Typeface.ITALIC);
// errorMessage.setClickable(false);
// entriesScrollView.removeView(entriesTable);
// headerFrame.setVisibility(View.VISIBLE);
// entriesScrollView.addView(errorMessage);
// }
//
// setLoading(false);
}
@Override
public void onListReturn(List<String> fieldList) {
// First we need header
headerRow = new TableRow(getActivity());
headerRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
for(int i =0;i<fieldList.size();i++){
TextView textView = new TextView(getActivity());
textView.setText(fieldList.get(i));
textView.setTypeface(null, Typeface.BOLD);
textView.setLayoutParams(layoutParams);
textView.setBackgroundResource(R.drawable.background_header);
textView.setPadding(HEADER_PADDING_LEFT, HEADER_PADDING_TOP, HEADER_PADDING_RIGHT, HEADER_PADDING_BOTTOM);
headerRow.addView(textView);
}
headerFrame.addView(headerRow);
Static.asyncDatabaseConnector.getRows(tableName, entriesLimit, page);
// // First we need header
// headerRow = new TableRow(getActivity());
// headerRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
// for(int i =0;i<fieldList.size();i++){
// TextView textView = new TextView(getActivity());
// textView.setText(fieldList.get(i));
// textView.setTypeface(null, Typeface.BOLD);
// textView.setLayoutParams(layoutParams);
// textView.setBackgroundResource(R.drawable.background_header);
// textView.setPadding(HEADER_PADDING_LEFT, HEADER_PADDING_TOP, HEADER_PADDING_RIGHT, HEADER_PADDING_BOTTOM);
// headerRow.addView(textView);
// }
// headerFrame.addView(headerRow);
//
// Static.asyncDatabaseConnector.getRows(tableName, entriesLimit, page);
}
@Override

View file

@ -6,6 +6,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceManager;
@ -13,12 +14,15 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
@ -29,7 +33,7 @@ import info.nerull7.mysqlbrowser.db.AsyncDatabaseConnector;
/**
* Created by nerull7 on 07.07.14.
*/
public class LoginFragment extends Fragment implements View.OnClickListener, AsyncDatabaseConnector.BooleanReturnListener {
public class LoginFragment extends Fragment implements View.OnClickListener, AsyncDatabaseConnector.BooleanReturnListener, AsyncDatabaseConnector.ListReturnListener {
private EditText urlTextbox;
private EditText loginTextbox;
private EditText passwordTextbox;
@ -94,8 +98,8 @@ public class LoginFragment extends Fragment implements View.OnClickListener, Asy
public void onBooleanReturn(boolean result) {
if(result) {
Static.asyncDatabaseConnector = asyncDatabaseConnector;
Intent intent = new Intent(getActivity(), DatabaseActivity.class);
startActivity(intent);
Static.asyncDatabaseConnector.setListReturnListener(this);
Static.asyncDatabaseConnector.getDatabases();
}
else {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
@ -115,4 +119,25 @@ public class LoginFragment extends Fragment implements View.OnClickListener, Asy
loginButton.setEnabled(true); // Now we can click button again
progressBar.setVisibility(View.INVISIBLE);
}
@Override
public void onListReturn(List<String> databases) {
if(databases!= null) {
Static.databases = databases;
Intent intent = new Intent(getActivity(), DatabaseActivity.class);
startActivity(intent);
}
// listAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, databases);
// databasesListView.setAdapter(listAdapter);
// databasesListView.setOnItemClickListener(this);
// } else {
// TextView errorMessage = new TextView(getActivity());
// errorMessage.setText(R.string.error_no_databases);
// errorMessage.setTypeface(null, Typeface.ITALIC);
// errorMessage.setClickable(false);
// rootView.addView(errorMessage);
// rootView.removeView(databasesListView);
// }
}
}

View file

@ -3,6 +3,8 @@ package info.nerull7.mysqlbrowser;
import android.content.Context;
import android.content.Intent;
import java.util.List;
import info.nerull7.mysqlbrowser.db.AsyncDatabaseConnector;
/**
@ -13,6 +15,11 @@ public class Static {
public static final String TABLE_NAME_ARG = "TableName";
public static AsyncDatabaseConnector asyncDatabaseConnector = null;
static List<String> tables;
static List<String> databases;
static List<String> header;
static List<List<String>> entries;
static int pageCount;
public static void startSettings(Context context){
Intent intent = new Intent(context, SettingsActivity.class);

View file

@ -4,6 +4,7 @@ import android.app.Fragment;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -23,13 +24,16 @@ import info.nerull7.mysqlbrowser.db.AsyncDatabaseConnector;
/**
* Created by nerull7 on 14.07.14.
*/
public class TableFragment extends Fragment implements AdapterView.OnItemClickListener, AsyncDatabaseConnector.ListReturnListener{
public class TableFragment extends Fragment implements AdapterView.OnItemClickListener, AsyncDatabaseConnector.ListReturnListener, AsyncDatabaseConnector.IntegerReturnListener, AsyncDatabaseConnector.MatrixReturnListener {
private String databaseName;
private ListView tablesList;
private ListAdapter listAdapter;
private RelativeLayout rootView;
private ProgressBar progressBar;
private int listenerCalled;
private String chosenTable;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -38,25 +42,12 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi
tablesList = (ListView) rootView.findViewById(R.id.tableList);
this.rootView = (RelativeLayout) rootView;
progressBar = (ProgressBar) rootView.findViewById(R.id.loginProgressBar);
Static.asyncDatabaseConnector.setListReturnListener(this);
Static.asyncDatabaseConnector.getTables();
return rootView;
}
listenerCalled = 0;
// Static.asyncDatabaseConnector.setListReturnListener(this);
// Static.asyncDatabaseConnector.getTables();
@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);
}
@Override
public void onListReturn(List<String> tables) {
if(tables != null) {
listAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, tables);
if(Static.tables != null) {
listAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, Static.tables);
tablesList.setAdapter(listAdapter);
tablesList.setOnItemClickListener(this);
} else {
@ -64,9 +55,73 @@ public class TableFragment extends Fragment implements AdapterView.OnItemClickLi
errorMessage.setText(R.string.error_no_tables);
errorMessage.setTypeface(null, Typeface.ITALIC);
errorMessage.setClickable(false);
rootView.addView(errorMessage);
rootView.removeView(tablesList);
this.rootView.addView(errorMessage);
this.rootView.removeView(tablesList);
}
progressBar.setVisibility(View.INVISIBLE);
return rootView;
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
chosenTable = (String) listAdapter.getItem(position);
listAdapter.getItem(position);
progressBar.setVisibility(View.VISIBLE);
Static.asyncDatabaseConnector.setIntegerReturnListener(this);
Static.asyncDatabaseConnector.setListReturnListener(this);
Static.asyncDatabaseConnector.setMatrixReturnListener(this);
int entriesLimit = PreferenceManager.getDefaultSharedPreferences(getActivity()).getInt(SettingsFragment.ENTRIES_PAGE_LIMIT, SettingsFragment.ENTRIES_PAGE_LIMIT_DEF);
Static.asyncDatabaseConnector.getRows(chosenTable, entriesLimit, 1);
Static.asyncDatabaseConnector.getFields(chosenTable);
Static.asyncDatabaseConnector.getEntriesCount(chosenTable);
}
@Override
public void onListReturn(List<String> header) {
// if(tables != null) {
// listAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, tables);
// tablesList.setAdapter(listAdapter);
// tablesList.setOnItemClickListener(this);
// } else {
// TextView errorMessage = new TextView(getActivity());
// errorMessage.setText(R.string.error_no_tables);
// errorMessage.setTypeface(null, Typeface.ITALIC);
// errorMessage.setClickable(false);
// rootView.addView(errorMessage);
// rootView.removeView(tablesList);
// }
// progressBar.setVisibility(View.INVISIBLE);
Static.header = header;
listenerCalled++;
if(listenerCalled==3)
startEntriesActivity();
}
@Override
public void onIntegerReturn(int result) {
Static.pageCount = result;
listenerCalled++;
if(listenerCalled==3)
startEntriesActivity();
}
@Override
public void onMatrixReturn(List<List<String>> data) {
Static.entries = data;
listenerCalled++;
if(listenerCalled==3)
startEntriesActivity();
}
private void startEntriesActivity() {
Intent intent = new Intent(getActivity(), EntriesActivity.class);
intent.putExtra(Static.DATABASE_NAME_ARG,databaseName);
intent.putExtra(Static.TABLE_NAME_ARG,chosenTable);
startActivity(intent);
}
}