|
@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.topic; |
|
|
|
|
|
|
|
|
import android.content.DialogInterface; |
|
|
import android.content.DialogInterface; |
|
|
import android.content.Intent; |
|
|
import android.content.Intent; |
|
|
import android.content.SharedPreferences; |
|
|
|
|
|
import android.os.AsyncTask; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.os.Handler; |
|
|
import android.os.Handler; |
|
@ -36,8 +35,6 @@ import mthmmy.utils.Report; |
|
|
import okhttp3.Request; |
|
|
import okhttp3.Request; |
|
|
import okhttp3.Response; |
|
|
import okhttp3.Response; |
|
|
|
|
|
|
|
|
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Activity for topics. When creating an Intent of this activity you need to bundle a <b>String</b> |
|
|
* Activity for topics. When creating an Intent of this activity you need to bundle a <b>String</b> |
|
|
* containing this topics's url using the key {@link #EXTRAS_TOPIC_URL} and a <b>String</b> containing |
|
|
* containing this topics's url using the key {@link #EXTRAS_TOPIC_URL} and a <b>String</b> containing |
|
@ -200,7 +197,7 @@ public class TopicActivity extends BaseActivity { |
|
|
topicTask.cancel(true); |
|
|
topicTask.cancel(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//--------------------------------------BOTTOM NAV BAR METHODS--------------------------------------
|
|
|
//--------------------------------------BOTTOM NAV BAR METHODS--------------------------------------
|
|
|
private void initIncrementButton(ImageButton increment, final int step) { |
|
|
private void initIncrementButton(ImageButton increment, final int step) { |
|
|
// Increment once for a click
|
|
|
// Increment once for a click
|
|
|
increment.setOnClickListener(new View.OnClickListener() { |
|
|
increment.setOnClickListener(new View.OnClickListener() { |
|
@ -333,7 +330,7 @@ public class TopicActivity extends BaseActivity { |
|
|
base_url = strings[0].substring(0, strings[0].lastIndexOf(".")); //This topic's base url
|
|
|
base_url = strings[0].substring(0, strings[0].lastIndexOf(".")); //This topic's base url
|
|
|
String newPageUrl = strings[0]; |
|
|
String newPageUrl = strings[0]; |
|
|
|
|
|
|
|
|
//Finds message focus if present
|
|
|
//Finds the index of message focus if present
|
|
|
{ |
|
|
{ |
|
|
postFocus = NO_POST_FOCUS; |
|
|
postFocus = NO_POST_FOCUS; |
|
|
if (newPageUrl.contains("msg")) { |
|
|
if (newPageUrl.contains("msg")) { |
|
@ -345,7 +342,16 @@ public class TopicActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!loadedPageUrl.contains(base_url)) { |
|
|
//Checks if the page to be loaded is the one already shown
|
|
|
|
|
|
if (!Objects.equals(loadedPageUrl, "") && !loadedPageUrl.contains(base_url)) { |
|
|
|
|
|
if (newPageUrl.contains("topicseen#new")) |
|
|
|
|
|
if (Integer.parseInt(loadedPageUrl.substring(base_url.length())) == numberOfPages) |
|
|
|
|
|
return SAME_PAGE; |
|
|
|
|
|
if (Objects.equals(loadedPageUrl.substring(base_url.length()) |
|
|
|
|
|
, newPageUrl.substring(base_url.length()))) |
|
|
|
|
|
return SAME_PAGE; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
loadedPageUrl = newPageUrl; |
|
|
loadedPageUrl = newPageUrl; |
|
|
Request request = new Request.Builder() |
|
|
Request request = new Request.Builder() |
|
|
.url(newPageUrl) |
|
|
.url(newPageUrl) |
|
@ -354,12 +360,6 @@ public class TopicActivity extends BaseActivity { |
|
|
Response response = client.newCall(request).execute(); |
|
|
Response response = client.newCall(request).execute(); |
|
|
document = Jsoup.parse(response.body().string()); |
|
|
document = Jsoup.parse(response.body().string()); |
|
|
parse(document); |
|
|
parse(document); |
|
|
for (int i = 0; i < postsList.size(); ++i) { |
|
|
|
|
|
if (postsList.get(i).getPostIndex() == postFocus) { |
|
|
|
|
|
postFocusPosition = i; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return SUCCESS; |
|
|
return SUCCESS; |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
Report.i(TAG, "IO Exception", e); |
|
|
Report.i(TAG, "IO Exception", e); |
|
@ -368,10 +368,17 @@ public class TopicActivity extends BaseActivity { |
|
|
Report.e(TAG, "Exception", e); |
|
|
Report.e(TAG, "Exception", e); |
|
|
return OTHER_ERROR; |
|
|
return OTHER_ERROR; |
|
|
} |
|
|
} |
|
|
} else return SAME_PAGE; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected void onPostExecute(Integer parseResult) { |
|
|
protected void onPostExecute(Integer parseResult) { |
|
|
|
|
|
//Finds the position of the focused message if present
|
|
|
|
|
|
for (int i = 0; i < postsList.size(); ++i) { |
|
|
|
|
|
if (postsList.get(i).getPostIndex() == postFocus) { |
|
|
|
|
|
postFocusPosition = i; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
switch (parseResult) { |
|
|
switch (parseResult) { |
|
|
case SUCCESS: |
|
|
case SUCCESS: |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
@ -397,6 +404,7 @@ public class TopicActivity extends BaseActivity { |
|
|
Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show(); |
|
|
break; |
|
|
break; |
|
|
case SAME_PAGE: |
|
|
case SAME_PAGE: |
|
|
|
|
|
//TODO change focus
|
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
//Parse failed - should never happen
|
|
|
//Parse failed - should never happen
|
|
|