Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/com/nietky/librarythingbrowser/BookListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class BookListActivity extends ListActivity {
int PROGRESS_SUCCESS = 4;
int PROGRESS_LOGIN_FAIL = 5;

static Boolean isLoggedIn = false;
Cursor cursor;
ArrayList<Integer> _ids = new ArrayList<Integer>();
ArrayList<Integer> toDeleteIds = new ArrayList<Integer>();
Expand Down Expand Up @@ -192,10 +193,11 @@ public void loadList() {
SearchHandler testSearchHandler = new SearchHandler(this);
testSearchHandler.setIds();
if (testSearchHandler.getIds().size() == 0) {
BookListActivity.setLoggedIn(false);
Intent in = new Intent(this, LoginActivity.class);
startActivity(in);
} else {

BookListActivity.setLoggedIn(true);
}
}

Expand Down Expand Up @@ -266,6 +268,14 @@ public void importData() {
task.execute(csvData);
}

public static void setLoggedIn(Boolean loggedIn) {
BookListActivity.isLoggedIn = loggedIn;
}

public static boolean getLoggedIn(){
return BookListActivity.isLoggedIn;
}

public class EntryParser implements CSVEntryParser<String[]> {
public String[] parseEntry(String... data) {
return data;
Expand Down Expand Up @@ -413,6 +423,7 @@ public void onClick(DialogInterface dialog,
DbHelperNew dbHelper = new DbHelperNew(
getApplicationContext());
dbHelper.delete();
BookListActivity.setLoggedIn(false);
loadList();
}

Expand Down Expand Up @@ -520,7 +531,7 @@ public void importBooksFromDownload(String downloadedContent) {
}

private class LTLoginDownload extends AsyncTask<Boolean, Integer, String> {
String result;
String result;
ProgressDialog dialog;


Expand All @@ -543,7 +554,8 @@ protected void onPreExecute() {
protected void onProgressUpdate(Integer... progUpdate) {
String METHOD = ".LTLoginDownload.onProgressUpdate()";

if (progUpdate[0] == PROGRESS_LOGGED_IN){
if (progUpdate[0] == PROGRESS_LOGGED_IN){
BookListActivity.setLoggedIn(true);
dialog.setMessage("Successfully logged in. Now downloading your library.");
if (!sharedPref.getBoolean("lt_remember_credentials", false)) {
prefsEdit = sharedPref.edit();
Expand All @@ -557,8 +569,10 @@ protected void onProgressUpdate(Integer... progUpdate) {
logger.log(TAG + METHOD, "Login failed.");
dialog.setMessage("Login failed.");
dialog.dismiss();
Intent in = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(in);
if(BookListActivity.getLoggedIn() == false){
Intent in = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(in);
}
}
}

Expand Down Expand Up @@ -592,8 +606,10 @@ protected String doInBackground(Boolean... bools) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.log(TAG + METHOD, "Login failed.");
this.publishProgress(PROGRESS_LOGIN_FAIL);
this.cancel(true);
loginPost.abort();
}

String loginResponseBody = "";
Expand All @@ -603,8 +619,10 @@ protected String doInBackground(Boolean... bools) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
logger.log(TAG + METHOD, "Login failed.");
this.publishProgress(PROGRESS_LOGIN_FAIL);
this.cancel(true);
loginPost.abort();
}

logger.log(TAG + METHOD, "loginResponseBody=" + loginResponseBody);
Expand Down