Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #147 from Sereri/master

Thread rating
  • Loading branch information...
commit 18862a5e3c2c7d24b14d2a60614b34e870b6771e 2 parents 101bb19 + 234eea0
@scottferg scottferg authored
View
BIN  res/drawable-hdpi/ic_menu_rate_thread.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
24 res/menu/post_menu.xml
@@ -13,22 +13,28 @@
android:title="@string/go_to"
/>
<item
+ android:id="@+id/refresh"
+ android:icon="@drawable/ic_menu_refresh"
+ android:title="@string/refresh"
+ />
+ <item
+ android:id="@+id/bookmark"
+ android:title="@string/bookmark"
+ android:icon="@drawable/ic_menu_star"
+ />
+ <item
+ android:id="@+id/rate_thread"
+ android:title="@string/rate_thread"
+ android:icon="@drawable/ic_menu_rate_thread"
+ />
+ <item
android:id="@+id/usercp"
android:icon="@drawable/ic_menu_usercp"
android:title="@string/usercp"
/>
<item
- android:id="@+id/refresh"
- android:icon="@drawable/ic_menu_refresh"
- android:title="@string/refresh" />
- <item
android:id="@+id/settings"
android:icon="@drawable/ic_menu_preferences"
android:title="@string/settings"
/>
- <item
- android:id="@+id/bookmark"
- android:title="@string/bookmark"
- android:icon="@drawable/ic_menu_star"
- />
</menu>
View
3  res/values/strings.xml
@@ -79,6 +79,7 @@
</string-array>
<string name="bookmark">Bookmark</string>
<string name="unbookmark">Unbookmark</string>
+ <string name="rate_thread">Rate Thread</string>
<string name="load_images">Load Images</string>
<string name="load_images_summary">If disabled, images are replaced with links.</string>
<string name="read_post_background2_color">Read Post Alternate Color</string>
@@ -102,4 +103,6 @@
<string name="show_smilies_summary">Show emotes or replace with :text: version.</string>
<string name="threadinfo">Thread info</string>
<string name="imgur_thumbnails">Imgur Thumbnails</string>
+ <string name="vote_failed">An error occured while voting, please try again</string>
+ <string name="vote_succeeded">You rated this thread %d, go hog wild</string>
</resources>
View
1,468 src/com/ferg/awful/ThreadDisplayFragment.java
@@ -45,11 +45,13 @@
import android.support.v4.app.Fragment;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import org.json.*;
import com.ferg.awful.constants.Constants;
+import com.ferg.awful.network.NetworkUtils;
import com.ferg.awful.preferences.AwfulPreferences;
import com.ferg.awful.preferences.ColorPickerPreference;
import com.ferg.awful.reply.Reply;
@@ -60,148 +62,155 @@
import com.ferg.awful.widget.SnapshotWebView;
public class ThreadDisplayFragment extends Fragment implements AwfulUpdateCallback {
- private static final String TAG = "ThreadDisplayActivity";
-
- private ThreadListAdapter mAdapter;
- private ParsePostQuoteTask mPostQuoteTask;
- private ParseEditPostTask mEditPostTask;
- private SharedPreferences mPrefs;
-
- private Handler mHandler = new Handler();
-
- private ImageButton mNext;
- private ImageButton mNextPage;
- private ImageButton mPrevPage;
- private ImageButton mReply;
- private ImageButton mRefresh;
- private ImageView mSnapshotView;
- private TextView mPageCountText;
- private TextView mTitle;
- private ProgressDialog mDialog;
- private ViewGroup mThreadWindow;
-
- private SnapshotWebView mThreadView;
-
- private boolean queueDataUpdate;
- private Bundle queueDataExtras;
- private boolean imagesLoadingState;
-
- private int savedPage = 0;
-
+ private static final String TAG = "ThreadDisplayActivity";
+
+ private ThreadListAdapter mAdapter;
+ private ParsePostQuoteTask mPostQuoteTask;
+ private ParseEditPostTask mEditPostTask;
+ private SharedPreferences mPrefs;
+
+ private Handler mHandler = new Handler();
+
+ private ImageButton mNext;
+ private ImageButton mNextPage;
+ private ImageButton mPrevPage;
+ private ImageButton mReply;
+ private ImageButton mRefresh;
+ private ImageView mSnapshotView;
+ private TextView mPageCountText;
+ private TextView mTitle;
+ private ProgressDialog mDialog;
+ private ViewGroup mThreadWindow;
+
+ private SnapshotWebView mThreadView;
+
+ private boolean queueDataUpdate;
+ private Bundle queueDataExtras;
+ private boolean imagesLoadingState;
+
+ private int savedPage = 0;
+
private String mPostJump = "";
-
- private WebViewClient callback = new WebViewClient(){
+
+ private WebViewClient callback = new WebViewClient() {
@Override
- public void onPageFinished(WebView view, String url){
- if(imagesLoadingState){
+ public void onPageFinished(WebView view, String url) {
+ if (imagesLoadingState) {
imagesLoadingState = false;
imageLoadingFinished();
}
- if(!isResumed()){
- Log.d(TAG,view.toString()+" pageFinished: "+url);
- mHandler.postDelayed(new Runnable(){
+ if (!isResumed()) {
+ Log.d(TAG, view.toString() + " pageFinished: " + url);
+ mHandler.postDelayed(new Runnable() {
@Override
public void run() {
pauseWebView();
}
- }, 500);//this seems to be a race condition. if we call the pause code too soon, it might ignore the message.
+ }, 500);// this seems to be a race condition. if we call the
+ // pause code too soon, it might ignore the message.
}
}
-
- public void onLoadResource (WebView view, String url){
- if(!imagesLoadingState && url != null && url.startsWith("http")){
+
+ public void onLoadResource(WebView view, String url) {
+ if (!imagesLoadingState && url != null && url.startsWith("http")) {
imagesLoadingState = true;
imageLoadingStarted();
}
}
- @Override
- public boolean shouldOverrideUrlLoading(WebView aView, String aUrl) {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(aUrl));
- PackageManager pacman = aView.getContext().getPackageManager();
- List<ResolveInfo> res = pacman.queryIntentActivities(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
- if(res.size() >0){
- aView.getContext().startActivity(browserIntent);
- }else{
- String[] split = aUrl.split(":");
- Toast.makeText(aView.getContext(), "No application found for protocol"+(split.length > 0 ? ": "+split[0] : ".") ,Toast.LENGTH_LONG).show();
- }
- return true;
- }
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView aView, String aUrl) {
+ Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(aUrl));
+ PackageManager pacman = aView.getContext().getPackageManager();
+ List<ResolveInfo> res = pacman.queryIntentActivities(browserIntent,
+ PackageManager.MATCH_DEFAULT_ONLY);
+ if (res.size() > 0) {
+ aView.getContext().startActivity(browserIntent);
+ } else {
+ String[] split = aUrl.split(":");
+ Toast.makeText(
+ aView.getContext(),
+ "No application found for protocol"
+ + (split.length > 0 ? ": " + split[0] : "."), Toast.LENGTH_LONG)
+ .show();
+ }
+ return true;
+ }
};
- @Override
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- setRetainInstance(true);
- }
-
- @Override
- public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedState) {
- super.onCreateView(aInflater, aContainer, aSavedState);
- View result = aInflater.inflate(R.layout.thread_display, aContainer, true);
-
- if (AwfulActivity.useLegacyActionbar()) {
- View actionbar = ((ViewStub) result.findViewById(R.id.actionbar)).inflate();
-
- mTitle = (TextView) actionbar.findViewById(R.id.title);
- mNext = (ImageButton) actionbar.findViewById(R.id.next_page);
- mReply = (ImageButton) actionbar.findViewById(R.id.reply);
- mRefresh = (ImageButton) actionbar.findViewById(R.id.refresh);
-
- mTitle.setMovementMethod(new ScrollingMovementMethod());
- }
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHasOptionsMenu(true);
+ setRetainInstance(true);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedState) {
+ super.onCreateView(aInflater, aContainer, aSavedState);
+ View result = aInflater.inflate(R.layout.thread_display, aContainer, true);
+
+ if (AwfulActivity.useLegacyActionbar()) {
+ View actionbar = ((ViewStub) result.findViewById(R.id.actionbar)).inflate();
+
+ mTitle = (TextView) actionbar.findViewById(R.id.title);
+ mNext = (ImageButton) actionbar.findViewById(R.id.next_page);
+ mReply = (ImageButton) actionbar.findViewById(R.id.reply);
+ mRefresh = (ImageButton) actionbar.findViewById(R.id.refresh);
+
+ mTitle.setMovementMethod(new ScrollingMovementMethod());
+ }
mPageCountText = (TextView) result.findViewById(R.id.page_count);
- mNextPage = (ImageButton) result.findViewById(R.id.next);
- mPrevPage = (ImageButton) result.findViewById(R.id.prev_page);
- mThreadView = (SnapshotWebView) result.findViewById(R.id.thread);
- mSnapshotView = (ImageView) result.findViewById(R.id.snapshot);
- mThreadWindow = (FrameLayout) result.findViewById(R.id.thread_window);
-
- return result;
- }
-
- @Override
- public void onActivityCreated(Bundle aSavedState) {
- super.onActivityCreated(aSavedState);
-
- if (AwfulActivity.useLegacyActionbar()) {
- mNext.setOnClickListener(onButtonClick);
- mReply.setOnClickListener(onButtonClick);
- mRefresh.setOnClickListener(onButtonClick);
- }
-
- initThreadViewProperties();
- }
-
- private void initThreadViewProperties() {
- mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
-
- mThreadView.resumeTimers();
- mThreadView.setWebViewClient(callback);
- mThreadView.setSnapshotView(mSnapshotView);
- mThreadView.getSettings().setJavaScriptEnabled(true);
- mThreadView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
- mThreadView.setBackgroundColor(mPrefs.getInt("default_post_background_color", getResources().getColor(R.color.background)));
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- mThreadView.getSettings().setEnableSmoothTransition(true);
- }
-
- mThreadView.setWebChromeClient(new WebChromeClient() {
- public void onConsoleMessage(String message, int lineNumber, String sourceID) {
- Log.d("Web Console", message + " -- From line " + lineNumber + " of " + sourceID);
- }
- });
- }
-
- private void initPageCountCallbacks() {
+ mNextPage = (ImageButton) result.findViewById(R.id.next);
+ mPrevPage = (ImageButton) result.findViewById(R.id.prev_page);
+ mThreadView = (SnapshotWebView) result.findViewById(R.id.thread);
+ mSnapshotView = (ImageView) result.findViewById(R.id.snapshot);
+ mThreadWindow = (FrameLayout) result.findViewById(R.id.thread_window);
+
+ return result;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle aSavedState) {
+ super.onActivityCreated(aSavedState);
+
+ if (AwfulActivity.useLegacyActionbar()) {
+ mNext.setOnClickListener(onButtonClick);
+ mReply.setOnClickListener(onButtonClick);
+ mRefresh.setOnClickListener(onButtonClick);
+ }
+
+ initThreadViewProperties();
+ }
+
+ private void initThreadViewProperties() {
+ mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
+
+ mThreadView.resumeTimers();
+ mThreadView.setWebViewClient(callback);
+ mThreadView.setSnapshotView(mSnapshotView);
+ mThreadView.getSettings().setJavaScriptEnabled(true);
+ mThreadView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
+ mThreadView.setBackgroundColor(mPrefs.getInt("default_post_background_color",
+ getResources().getColor(R.color.background)));
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ mThreadView.getSettings().setEnableSmoothTransition(true);
+ }
+
+ mThreadView.setWebChromeClient(new WebChromeClient() {
+ public void onConsoleMessage(String message, int lineNumber, String sourceID) {
+ Log.d("Web Console", message + " -- From line " + lineNumber + " of " + sourceID);
+ }
+ });
+ }
+
+ private void initPageCountCallbacks() {
mPrevPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- mThreadView.loadData("", "text/html", "utf-8");
+ mThreadView.loadData("", "text/html", "utf-8");
goToPage(mAdapter.getPage() - 1);
}
});
@@ -214,628 +223,649 @@ public void onClick(View v) {
if (mAdapter.getPage() == mAdapter.getLastPage()) {
mNextPage.setImageResource(R.drawable.stat_notify_sync);
- mNextPage.setOnClickListener(new View.OnClickListener(){
+ mNextPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- mThreadView.loadData("", "text/html", "utf-8");
+ mThreadView.loadData("", "text/html", "utf-8");
mAdapter.refresh();
}
});
} else {
mNextPage.setImageResource(R.drawable.r_arrow);
- mNextPage.setOnClickListener(onButtonClick);
- }
-
- mNextPage.setVisibility(View.VISIBLE);
- }
-
- private boolean isTablet() {
- return ((AwfulActivity) getActivity()).isTablet();
- }
-
- private void setActionbarTitle(String aTitle) {
- if (AwfulActivity.useLegacyActionbar()) {
- mTitle.setText(Html.fromHtml(aTitle));
- } else {
- ((ThreadDisplayActivity) getActivity()).setThreadTitle(aTitle);
- }
- }
-
- @Override
- public void onStart() {
- super.onStart();
-
- setActionbarTitle(mAdapter.getTitle());
- }
-
- public void setListAdapter(ThreadListAdapter adapter){
- mAdapter = (ThreadListAdapter) adapter;
-
- if (mAdapter.getChildCount() > 0) {
- dataUpdate(false,null);
- }
- }
-
- @Override
- public void onPause() {
- super.onPause();
- try {
- mThreadView.pauseTimers();
- mThreadView.stopLoading();
- Class.forName("android.webkit.WebView").getMethod("onPause", (Class[]) null)
- .invoke(mThreadView, (Object[]) null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- if(getActivity() != null && getActivity().getIntent() != null){
- getActivity().getIntent().putExtra(Constants.PAGE, mAdapter.getPage());
- }
-
- cleanupTasks();
- }
-
- public void pauseWebView(){
- try {
- mThreadView.pauseTimers();
- Class.forName("android.webkit.WebView").getMethod("onPause", (Class[]) null)
- .invoke(mThreadView, (Object[]) null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void onStop() {
- super.onStop();
- mThreadView.stopLoading();
- cleanupTasks();
- }
-
- @Override
- public void onDetach() {
- super.onDetach();
- savedPage = mAdapter.getPage(); // saves page for orientation change.
- }
-
- @Override
- public void onDestroyView(){
- super.onDestroyView();
- try {
- mThreadWindow.removeView(mThreadView);
- mThreadView.destroy();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- cleanupTasks();
- }
-
- private void cleanupTasks() {
- if (mDialog != null) {
- }
- if (mEditPostTask != null) {
- mEditPostTask.cancel(true);
- }
-
- if (mPostQuoteTask != null) {
- mPostQuoteTask.cancel(true);
- }
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- if (mThreadWindow.getChildCount() < 2) {
- mThreadView = new SnapshotWebView(getActivity());
-
- initThreadViewProperties();
-
- mThreadWindow.addView(mThreadView, new ViewGroup.LayoutParams(
- ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
-
- populateThreadView();
- }else{
- if(mThreadView != null){
- try {
- Class.forName("android.webkit.WebView").getMethod("onResume", (Class[]) null)
- .invoke(mThreadView, (Object[]) null);
- mThreadView.resumeTimers();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- if (queueDataUpdate){
- delayedDataUpdate(queueDataExtras);
- queueDataUpdate = false;
- queueDataExtras = null;
- }
-
- }
-
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- if(menu.size() == 0){
- inflater.inflate(R.menu.post_menu, menu);
- }
- }
-
- @Override
- public void onPrepareOptionsMenu(Menu menu) {
- if(menu == null || !AwfulActivity.useLegacyActionbar()){
- return;
- }
-
- MenuItem bk = menu.findItem(R.id.bookmark);
-
- if(bk != null){
- AwfulThread th = (AwfulThread) mAdapter.getState();
- if(th != null){
- bk.setTitle((th.isBookmarked()? getString(R.string.unbookmark):getString(R.string.bookmark)));
- }
- }
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch(item.getItemId()) {
- case R.id.next_page:
- showNextPage();
- break;
- case R.id.reply:
- displayPostReplyDialog();
- break;
- case R.id.go_back:
- goToPage(mAdapter.getPage()-1);
- break;
- case R.id.usercp:
- displayUserCP();
- break;
- case R.id.go_to:
- displayPagePicker();
- break;
- case R.id.refresh:
- refresh();
- break;
- case R.id.settings:
- startActivity(new Intent().setClass(getActivity(), SettingsActivity.class));
- break;
- case R.id.bookmark:
- mAdapter.toggleBookmark();
- break;
- default:
- return super.onOptionsItemSelected(item);
- }
-
- return true;
- }
-
- @Override
- public void onSaveInstanceState(Bundle aOutState) {
- super.onSaveInstanceState(aOutState);
- }
-
- private void displayUserCP() {
- if (!isTablet()) {
- startActivity(new Intent().setClass(getActivity(), UserCPActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
- } else {
- UserCPFragment.newInstance(true).show(getFragmentManager(), "user_control_panel_dialog");
- }
- }
-
- private void displayPagePicker() {
- final NumberPicker jumpToText = new NumberPicker(getActivity());
- jumpToText.setRange(1, mAdapter.getLastPage());
- jumpToText.setCurrent(mAdapter.getPage());
- new AlertDialog.Builder(getActivity())
- .setTitle("Jump to Page")
- .setView(jumpToText)
- .setPositiveButton("OK",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface aDialog, int aWhich) {
- try {
- int pageInt = jumpToText.getCurrent();
- if (pageInt > 0 && pageInt <= mAdapter.getLastPage()) {
- goToPage(pageInt);
- }
- } catch (NumberFormatException e) {
- Toast.makeText(getActivity(),
- R.string.invalid_page, Toast.LENGTH_SHORT).show();
- } catch (Exception e) {
- Log.d(TAG, e.toString());
- }
- }
- })
- .setNegativeButton("Cancel", null)
- .show();
- }
-
- private boolean onPostActionItemSelected(int aItem, String aPostId, String aLastReadUrl, String aUsername) {
- switch (aItem) {
- case ClickInterface.EDIT:
- if (aUsername != null){
- if (!isTablet()) {
- startActivity(new Intent(getActivity(), MessageDisplayActivity.class).putExtra(Constants.PARAM_USERNAME, aUsername));
- } else {
- MessageFragment.newInstance(aUsername, 0).show(getFragmentManager(), "new_private_message_dialog");
- }
- }else{
- mEditPostTask = new ParseEditPostTask();
- mEditPostTask.execute(aPostId);
- }
- return true;
- case ClickInterface.QUOTE:
- mPostQuoteTask = new ParsePostQuoteTask();
- mPostQuoteTask.execute(aPostId);
- return true;
- case ClickInterface.LAST_READ:
- mAdapter.markLastRead(aLastReadUrl);
- return true;
- }
-
- return false;
- }
-
- @Override
- public void onActivityResult(int aRequestCode, int aResultCode, Intent aData) {
- // If we're here because of a post result, refresh the thread
- switch (aResultCode) {
- case PostReplyFragment.RESULT_POSTED:
- refresh();
- break;
- }
- }
-
- public void refresh() {
- mAdapter.refresh();
- }
-
- private View.OnClickListener onButtonClick = new View.OnClickListener() {
- public void onClick(View aView) {
- switch (aView.getId()) {
- case R.id.next_page:
- case R.id.next:
- showNextPage();
- break;
- case R.id.reply:
- displayPostReplyDialog();
- break;
- case R.id.refresh:
- if(imagesLoadingState && mThreadView != null){
- mThreadView.stopLoading();
- imagesLoadingState = false;
- imageLoadingFinished();
- }else{
- refresh();
- }
- break;
- }
- }
- };
-
- private void showNextPage() {
- if (mAdapter.getPage() < mAdapter.getLastPage()) {
- mThreadView.loadData("", "text/html", "utf-8");
- goToPage(mAdapter.getPage()+1);
- }
- }
-
- private void displayPostReplyDialog() {
- Bundle args = new Bundle();
- args.putString(Constants.THREAD, mAdapter.getState().getID() + "");
-
- displayPostReplyDialog(args);
- }
-
- private void displayPostReplyDialog(Bundle aArgs) {
- if (isTablet()) {
- PostReplyFragment fragment = PostReplyFragment.newInstance(aArgs);
- fragment.setTargetFragment(this, 0);
- fragment.show(getActivity().getSupportFragmentManager(), "post_reply_dialog");
- } else {
- Intent postReply = new Intent().setClass(getActivity(),
- PostReplyActivity.class);
- postReply.putExtras(aArgs);
- startActivityForResult(postReply, 0);
- }
- }
-
- private class ParseEditPostTask extends AsyncTask<String, Void, String> {
- private String mPostId = null;
-
- public void onPreExecute() {
- mDialog = ProgressDialog.show(getActivity(), "Loading",
- "Hold on...", true);
- }
-
- public String doInBackground(String... aParams) {
- String result = null;
-
- if (!isCancelled()) {
- try {
- mPostId = aParams[0];
-
- result = Reply.getPost(mPostId);
- } catch (Exception e) {
- e.printStackTrace();
- Log.i(TAG, e.toString());
- }
- }
- return result;
- }
-
- public void onPostExecute(String aResult) {
- if (!isCancelled()) {
- if (mDialog != null) {
- mDialog.dismiss();
- }
-
- Bundle args = new Bundle();
-
- args.putString(Constants.THREAD, mAdapter.getState().getID()+"");
- args.putString(Constants.QUOTE, aResult);
- args.putBoolean(Constants.EDITING, true);
- args.putString(Constants.POST_ID, mPostId);
-
- displayPostReplyDialog(args);
- }
- }
- }
-
- private class ParsePostQuoteTask extends AsyncTask<String, Void, String> {
- public void onPreExecute() {
- mDialog = ProgressDialog.show(getActivity(), "Loading", "Hold on...", true);
- }
-
- public String doInBackground(String... aParams) {
- String result = null;
-
- if (!isCancelled()) {
- try {
- result = Reply.getQuote(aParams[0]);
- } catch (Exception e) {
- e.printStackTrace();
- Log.i(TAG, e.toString());
- }
- }
- return result;
- }
-
- public void onPostExecute(String aResult) {
- if (!isCancelled()) {
- if (mDialog != null) {
- mDialog.dismiss();
- }
-
- Bundle args = new Bundle();
- args.putString(Constants.THREAD, Integer.toString(mAdapter.getState().getID()));
- args.putString(Constants.QUOTE, aResult);
-
- displayPostReplyDialog(args);
- }
- }
- }
-
- @Override
- public void dataUpdate(boolean pageChange, Bundle extras) {
- if (!this.isResumed()) {
- queueDataUpdate = true;
- queueDataExtras = extras;
- } else {
- queueDataUpdate = false;
- queueDataExtras = null;
- delayedDataUpdate(extras);
- }
- }
-
- public void delayedDataUpdate(Bundle extras) {
- setActionbarTitle(mAdapter.getTitle());
-
- if (AwfulActivity.useLegacyActionbar()) {
- if (mAdapter.getPage() == mAdapter.getLastPage()) {
- mNext.setVisibility(View.GONE);
- } else {
- mNext.setVisibility(View.VISIBLE);
- }
-
- if(mAdapter.getThreadClosed()){
- mReply.setVisibility(View.GONE);
- } else {
- mReply.setVisibility(View.VISIBLE);
- }
- }
- populateThreadView();
- }
-
- public int getSavedPage() {
- return savedPage;
- }
-
- @Override
- public void loadingFailed() {
- if (AwfulActivity.useLegacyActionbar()) {
- mRefresh.setVisibility(View.VISIBLE);
- mRefresh.setAnimation(null);
- mRefresh.setImageResource(android.R.drawable.ic_dialog_alert);
- mRefresh.startAnimation(mAdapter.getBlinkingAnimation());
- } else {
- getActivity().setProgressBarIndeterminateVisibility(false);
- }
-
- Toast.makeText(getActivity(), "Loading Failed!", Toast.LENGTH_LONG).show();
- }
-
- @Override
- public void loadingStarted() {
- if (AwfulActivity.useLegacyActionbar()) {
- mRefresh.setVisibility(View.VISIBLE);
- mRefresh.setImageResource(R.drawable.ic_menu_refresh);
- mRefresh.startAnimation(mAdapter.getRotateAnimation());
- } else {
- getActivity().setProgressBarIndeterminateVisibility(true);
- }
- }
-
- @Override
- public void loadingSucceeded() {
- if (AwfulActivity.useLegacyActionbar()) {
- mRefresh.setAnimation(null);
- mRefresh.setVisibility(View.GONE);
- } else {
- getActivity().setProgressBarIndeterminateVisibility(false);
- }
- }
-
- public void imageLoadingStarted() {
- if (AwfulActivity.useLegacyActionbar()) {
- if(mRefresh != null){
- mRefresh.setVisibility(View.VISIBLE);
- mRefresh.setImageResource(android.R.drawable.ic_menu_mapmode);
- mRefresh.startAnimation(mAdapter.getBlinkingAnimation());
- }
- } else {
- getActivity().setProgressBarIndeterminateVisibility(true);
- }
- }
-
- public void imageLoadingFinished() {
- if (AwfulActivity.useLegacyActionbar()) {
- if(mRefresh != null){
- mRefresh.setAnimation(null);
- mRefresh.setVisibility(View.GONE);
- }
- } else {
- getActivity().setProgressBarIndeterminateVisibility(false);
- }
- }
-
- private void populateThreadView() {
+ mNextPage.setOnClickListener(onButtonClick);
+ }
+
+ mNextPage.setVisibility(View.VISIBLE);
+ }
+
+ private boolean isTablet() {
+ return ((AwfulActivity) getActivity()).isTablet();
+ }
+
+ private void setActionbarTitle(String aTitle) {
+ if (AwfulActivity.useLegacyActionbar()) {
+ mTitle.setText(Html.fromHtml(aTitle));
+ } else {
+ ((ThreadDisplayActivity) getActivity()).setThreadTitle(aTitle);
+ }
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ setActionbarTitle(mAdapter.getTitle());
+ }
+
+ public void setListAdapter(ThreadListAdapter adapter) {
+ mAdapter = (ThreadListAdapter) adapter;
+
+ if (mAdapter.getChildCount() > 0) {
+ dataUpdate(false, null);
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ try {
+ mThreadView.pauseTimers();
+ mThreadView.stopLoading();
+ Class.forName("android.webkit.WebView").getMethod("onPause", (Class[]) null)
+ .invoke(mThreadView, (Object[]) null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ if (getActivity() != null && getActivity().getIntent() != null) {
+ getActivity().getIntent().putExtra(Constants.PAGE, mAdapter.getPage());
+ }
+
+ cleanupTasks();
+ }
+
+ public void pauseWebView() {
+ try {
+ mThreadView.pauseTimers();
+ Class.forName("android.webkit.WebView").getMethod("onPause", (Class[]) null)
+ .invoke(mThreadView, (Object[]) null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ mThreadView.stopLoading();
+ cleanupTasks();
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ savedPage = mAdapter.getPage(); // saves page for orientation change.
+ }
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ try {
+ mThreadWindow.removeView(mThreadView);
+ mThreadView.destroy();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ cleanupTasks();
+ }
+
+ private void cleanupTasks() {
+ if (mDialog != null) {
+ }
+ if (mEditPostTask != null) {
+ mEditPostTask.cancel(true);
+ }
+
+ if (mPostQuoteTask != null) {
+ mPostQuoteTask.cancel(true);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ if (mThreadWindow.getChildCount() < 2) {
+ mThreadView = new SnapshotWebView(getActivity());
+
+ initThreadViewProperties();
+
+ mThreadWindow.addView(mThreadView, new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
+
+ populateThreadView();
+ } else {
+ if (mThreadView != null) {
+ try {
+ Class.forName("android.webkit.WebView").getMethod("onResume", (Class[]) null)
+ .invoke(mThreadView, (Object[]) null);
+ mThreadView.resumeTimers();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ if (queueDataUpdate) {
+ delayedDataUpdate(queueDataExtras);
+ queueDataUpdate = false;
+ queueDataExtras = null;
+ }
+
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ if (menu.size() == 0) {
+ inflater.inflate(R.menu.post_menu, menu);
+ }
+ }
+
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ if (menu == null || !AwfulActivity.useLegacyActionbar()) {
+ return;
+ }
+
+ MenuItem bk = menu.findItem(R.id.bookmark);
+
+ if (bk != null) {
+ AwfulThread th = (AwfulThread) mAdapter.getState();
+ if (th != null) {
+ bk.setTitle((th.isBookmarked() ? getString(R.string.unbookmark)
+ : getString(R.string.bookmark)));
+ }
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.next_page:
+ showNextPage();
+ break;
+ case R.id.reply:
+ displayPostReplyDialog();
+ break;
+ case R.id.go_back:
+ goToPage(mAdapter.getPage()-1);
+ break;
+ case R.id.usercp:
+ displayUserCP();
+ break;
+ case R.id.go_to:
+ displayPagePicker();
+ break;
+ case R.id.refresh:
+ refresh();
+ break;
+ case R.id.settings:
+ startActivity(new Intent().setClass(getActivity(), SettingsActivity.class));
+ break;
+ case R.id.bookmark:
+ mAdapter.toggleBookmark();
+ break;
+ case R.id.rate_thread:
+ rateThread();
+ break;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+
+ return true;
+ }
+
+ private void rateThread() {
+
+ final CharSequence[] items = { "1", "2", "3", "4", "5" };
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
+ builder.setTitle("Rate this thread");
+ builder.setItems(items, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ HashMap<String, String> params = new HashMap<String, String>();
+ params.put(Constants.PARAM_THREAD_ID, String.valueOf(mAdapter.getId()));
+ params.put(Constants.PARAM_VOTE, String.valueOf(item+1));
+ try {
+ NetworkUtils.post(Constants.FUNCTION_RATE_THREAD, params);
+ } catch (Exception e) {
+ Toast errorToast = Toast.makeText(getActivity(), R.string.vote_failed, Toast.LENGTH_LONG);
+ errorToast.show();
+ e.printStackTrace();
+ }
+ Toast successToast = Toast.makeText(getActivity(), String.format(getString(R.string.vote_succeeded), item+1), Toast.LENGTH_LONG);
+ successToast.show();
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.show();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle aOutState) {
+ super.onSaveInstanceState(aOutState);
+ }
+
+ private void displayUserCP() {
+ if (!isTablet()) {
+ startActivity(new Intent().setClass(getActivity(), UserCPActivity.class).addFlags(
+ Intent.FLAG_ACTIVITY_CLEAR_TOP));
+ } else {
+ UserCPFragment.newInstance(true)
+ .show(getFragmentManager(), "user_control_panel_dialog");
+ }
+ }
+
+ private void displayPagePicker() {
+ final NumberPicker jumpToText = new NumberPicker(getActivity());
+ jumpToText.setRange(1, mAdapter.getLastPage());
+ jumpToText.setCurrent(mAdapter.getPage());
+ new AlertDialog.Builder(getActivity()).setTitle("Jump to Page").setView(jumpToText)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface aDialog, int aWhich) {
+ try {
+ int pageInt = jumpToText.getCurrent();
+ if (pageInt > 0 && pageInt <= mAdapter.getLastPage()) {
+ goToPage(pageInt);
+ }
+ } catch (NumberFormatException e) {
+ Toast.makeText(getActivity(), R.string.invalid_page, Toast.LENGTH_SHORT)
+ .show();
+ } catch (Exception e) {
+ Log.d(TAG, e.toString());
+ }
+ }
+ }).setNegativeButton("Cancel", null).show();
+ }
+
+ private boolean onPostActionItemSelected(int aItem, String aPostId, String aLastReadUrl,
+ String aUsername) {
+ switch (aItem) {
+ case ClickInterface.EDIT:
+ if (aUsername != null) {
+ if (!isTablet()) {
+ startActivity(new Intent(getActivity(), MessageDisplayActivity.class).putExtra(
+ Constants.PARAM_USERNAME, aUsername));
+ } else {
+ MessageFragment.newInstance(aUsername, 0).show(getFragmentManager(),
+ "new_private_message_dialog");
+ }
+ } else {
+ mEditPostTask = new ParseEditPostTask();
+ mEditPostTask.execute(aPostId);
+ }
+ return true;
+ case ClickInterface.QUOTE:
+ mPostQuoteTask = new ParsePostQuoteTask();
+ mPostQuoteTask.execute(aPostId);
+ return true;
+ case ClickInterface.LAST_READ:
+ mAdapter.markLastRead(aLastReadUrl);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void onActivityResult(int aRequestCode, int aResultCode, Intent aData) {
+ // If we're here because of a post result, refresh the thread
+ switch (aResultCode) {
+ case PostReplyFragment.RESULT_POSTED:
+ refresh();
+ break;
+ }
+ }
+
+ public void refresh() {
+ mAdapter.refresh();
+ }
+
+ private View.OnClickListener onButtonClick = new View.OnClickListener() {
+ public void onClick(View aView) {
+ switch (aView.getId()) {
+ case R.id.next_page:
+ case R.id.next:
+ showNextPage();
+ break;
+ case R.id.reply:
+ displayPostReplyDialog();
+ break;
+ case R.id.refresh:
+ if (imagesLoadingState && mThreadView != null) {
+ mThreadView.stopLoading();
+ imagesLoadingState = false;
+ imageLoadingFinished();
+ } else {
+ refresh();
+ }
+ break;
+ }
+ }
+ };
+
+ private void showNextPage() {
+ if (mAdapter.getPage() < mAdapter.getLastPage()) {
+ mThreadView.loadData("", "text/html", "utf-8");
+ goToPage(mAdapter.getPage() + 1);
+ }
+ }
+
+ private void displayPostReplyDialog() {
+ Bundle args = new Bundle();
+ args.putString(Constants.THREAD, mAdapter.getState().getID() + "");
+
+ displayPostReplyDialog(args);
+ }
+
+ private void displayPostReplyDialog(Bundle aArgs) {
+ if (isTablet()) {
+ PostReplyFragment fragment = PostReplyFragment.newInstance(aArgs);
+ fragment.setTargetFragment(this, 0);
+ fragment.show(getActivity().getSupportFragmentManager(), "post_reply_dialog");
+ } else {
+ Intent postReply = new Intent().setClass(getActivity(), PostReplyActivity.class);
+ postReply.putExtras(aArgs);
+ startActivityForResult(postReply, 0);
+ }
+ }
+
+ private class ParseEditPostTask extends AsyncTask<String, Void, String> {
+ private String mPostId = null;
+
+ public void onPreExecute() {
+ mDialog = ProgressDialog.show(getActivity(), "Loading", "Hold on...", true);
+ }
+
+ public String doInBackground(String... aParams) {
+ String result = null;
+
+ if (!isCancelled()) {
+ try {
+ mPostId = aParams[0];
+
+ result = Reply.getPost(mPostId);
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.i(TAG, e.toString());
+ }
+ }
+ return result;
+ }
+
+ public void onPostExecute(String aResult) {
+ if (!isCancelled()) {
+ if (mDialog != null) {
+ mDialog.dismiss();
+ }
+
+ Bundle args = new Bundle();
+
+ args.putString(Constants.THREAD, mAdapter.getState().getID() + "");
+ args.putString(Constants.QUOTE, aResult);
+ args.putBoolean(Constants.EDITING, true);
+ args.putString(Constants.POST_ID, mPostId);
+
+ displayPostReplyDialog(args);
+ }
+ }
+ }
+
+ private class ParsePostQuoteTask extends AsyncTask<String, Void, String> {
+ public void onPreExecute() {
+ mDialog = ProgressDialog.show(getActivity(), "Loading", "Hold on...", true);
+ }
+
+ public String doInBackground(String... aParams) {
+ String result = null;
+
+ if (!isCancelled()) {
+ try {
+ result = Reply.getQuote(aParams[0]);
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.i(TAG, e.toString());
+ }
+ }
+ return result;
+ }
+
+ public void onPostExecute(String aResult) {
+ if (!isCancelled()) {
+ if (mDialog != null) {
+ mDialog.dismiss();
+ }
+
+ Bundle args = new Bundle();
+ args.putString(Constants.THREAD, Integer.toString(mAdapter.getState().getID()));
+ args.putString(Constants.QUOTE, aResult);
+
+ displayPostReplyDialog(args);
+ }
+ }
+ }
+
+ @Override
+ public void dataUpdate(boolean pageChange, Bundle extras) {
+ if (!this.isResumed()) {
+ queueDataUpdate = true;
+ queueDataExtras = extras;
+ } else {
+ queueDataUpdate = false;
+ queueDataExtras = null;
+ delayedDataUpdate(extras);
+ }
+ }
+
+ public void delayedDataUpdate(Bundle extras) {
+ setActionbarTitle(mAdapter.getTitle());
+
+ if (AwfulActivity.useLegacyActionbar()) {
+ if (mAdapter.getPage() == mAdapter.getLastPage()) {
+ mNext.setVisibility(View.GONE);
+ } else {
+ mNext.setVisibility(View.VISIBLE);
+ }
+
+ if (mAdapter.getThreadClosed()) {
+ mReply.setVisibility(View.GONE);
+ } else {
+ mReply.setVisibility(View.VISIBLE);
+ }
+ }
+ populateThreadView();
+ }
+
+ public int getSavedPage() {
+ return savedPage;
+ }
+
+ @Override
+ public void loadingFailed() {
+ if (AwfulActivity.useLegacyActionbar()) {
+ mRefresh.setVisibility(View.VISIBLE);
+ mRefresh.setAnimation(null);
+ mRefresh.setImageResource(android.R.drawable.ic_dialog_alert);
+ mRefresh.startAnimation(mAdapter.getBlinkingAnimation());
+ } else {
+ getActivity().setProgressBarIndeterminateVisibility(false);
+ }
+
+ Toast.makeText(getActivity(), "Loading Failed!", Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void loadingStarted() {
+ if (AwfulActivity.useLegacyActionbar()) {
+ mRefresh.setVisibility(View.VISIBLE);
+ mRefresh.setImageResource(R.drawable.ic_menu_refresh);
+ mRefresh.startAnimation(mAdapter.getRotateAnimation());
+ } else {
+ getActivity().setProgressBarIndeterminateVisibility(true);
+ }
+ }
+
+ @Override
+ public void loadingSucceeded() {
+ if (AwfulActivity.useLegacyActionbar()) {
+ mRefresh.setAnimation(null);
+ mRefresh.setVisibility(View.GONE);
+ } else {
+ getActivity().setProgressBarIndeterminateVisibility(false);
+ }
+ }
+
+ public void imageLoadingStarted() {
+ if (AwfulActivity.useLegacyActionbar()) {
+ if (mRefresh != null) {
+ mRefresh.setVisibility(View.VISIBLE);
+ mRefresh.setImageResource(android.R.drawable.ic_menu_mapmode);
+ mRefresh.startAnimation(mAdapter.getBlinkingAnimation());
+ }
+ } else {
+ getActivity().setProgressBarIndeterminateVisibility(true);
+ }
+ }
+
+ public void imageLoadingFinished() {
+ if (AwfulActivity.useLegacyActionbar()) {
+ if (mRefresh != null) {
+ mRefresh.setAnimation(null);
+ mRefresh.setVisibility(View.GONE);
+ }
+ } else {
+ getActivity().setProgressBarIndeterminateVisibility(false);
+ }
+ }
+
+ private void populateThreadView() {
initPageCountCallbacks();
-
- mPageCountText.setText("Page " + mAdapter.getPage() + "/" + mAdapter.getLastPage());
-
- try {
- mThreadView.addJavascriptInterface(new ClickInterface(), "listener");
- mThreadView.addJavascriptInterface(getSerializedPreferences(new AwfulPreferences(getActivity())), "preferences");
-
- mThreadView.loadDataWithBaseURL("http://forums.somethingawful.com",
- AwfulThread.getHtml((ArrayList<AwfulPost>) mAdapter.getChildren(),
- new AwfulPreferences(getActivity()), isTablet()), "text/html", "utf-8", null);
- } catch (NullPointerException e) {
- // If we've already left the activity the webview may still be working to populate,
- // just log it
- }
- }
-
- private String getSerializedPreferences(final AwfulPreferences aAppPrefs) {
- JSONObject result = new JSONObject();
-
- try {
- result.put("username", aAppPrefs.username);
- result.put("userQuote", "#a2cd5a");
- result.put("usernameHighlight", "#9933ff");
- result.put("youtubeHighlight", "#ff00ff");
- result.put("showSpoilers", aAppPrefs.showAllSpoilers);
- result.put("postcolor", ColorPickerPreference.convertToARGB(aAppPrefs.postFontColor));
- result.put("backgroundcolor", ColorPickerPreference.convertToARGB(aAppPrefs.postBackgroundColor));
- result.put("linkQuoteColor", ColorPickerPreference.convertToARGB(aAppPrefs.postLinkQuoteColor));
- result.put("highlightUserQuote", Boolean.toString(aAppPrefs.highlightUserQuote));
- result.put("highlightUsername", Boolean.toString(aAppPrefs.highlightUsername));
- result.put("postjumpid", mPostJump);
- } catch (JSONException e) {
- }
-
- return result.toString();
- }
-
- private class ClickInterface {
- public static final int QUOTE = 0;
- public static final int LAST_READ = 1;
- public static final int EDIT = 2;
-
- final CharSequence[] mEditablePostItems = {
- "Quote",
- "Mark last read",
- "Edit Post"
- };
- final CharSequence[] mPostItems = {
- "Quote",
- "Mark last read",
- "Send Private Message"
- };
-
- // Post ID is the item tapped
- public void onPostClick(final String aPostId, final String aLastReadUrl, final String aUsername) {
- new AlertDialog.Builder(getActivity())
- .setTitle("Select an Action")
- .setItems(mPostItems, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface aDialog, int aItem) {
- onPostActionItemSelected(aItem, aPostId, aLastReadUrl, aUsername);
- }
- })
- .show();
- }
-
- // Post ID is the item tapped
- public void onEditablePostClick(final String aPostId, final String aLastReadUrl) {
- new AlertDialog.Builder(getActivity())
- .setTitle("Select an Action")
- .setItems(mEditablePostItems, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface aDialog, int aItem) {
- onPostActionItemSelected(aItem, aPostId, aLastReadUrl, null);
- }
- })
- .show();
- }
-
- public void onPreviousPageClick() {
- getActivity().runOnUiThread(new Runnable() {
- public void run() {
- goToPage(mAdapter.getPage() - 1);
- }
- });
- }
-
- public void onNextPageClick() {
- getActivity().runOnUiThread(new Runnable() {
- public void run() {
- goToPage(mAdapter.getPage() + 1);
- }
- });
- }
-
- public void onRefreshPageClick() {
- getActivity().runOnUiThread(new Runnable() {
- public void run() {
- refresh();
- }
- });
- }
- }
+
+ mPageCountText.setText("Page " + mAdapter.getPage() + "/" + mAdapter.getLastPage());
+
+ try {
+ mThreadView.addJavascriptInterface(new ClickInterface(), "listener");
+ mThreadView.addJavascriptInterface(getSerializedPreferences(new AwfulPreferences(
+ getActivity())), "preferences");
+
+ mThreadView.loadDataWithBaseURL("http://forums.somethingawful.com", AwfulThread
+ .getHtml((ArrayList<AwfulPost>) mAdapter.getChildren(), new AwfulPreferences(
+ getActivity()), isTablet()), "text/html", "utf-8", null);
+ } catch (NullPointerException e) {
+ // If we've already left the activity the webview may still be
+ // working to populate,
+ // just log it
+ }
+ }
+
+ private String getSerializedPreferences(final AwfulPreferences aAppPrefs) {
+ JSONObject result = new JSONObject();
+
+ try {
+ result.put("username", aAppPrefs.username);
+ result.put("userQuote", "#a2cd5a");
+ result.put("usernameHighlight", "#9933ff");
+ result.put("youtubeHighlight", "#ff00ff");
+ result.put("showSpoilers", aAppPrefs.showAllSpoilers);
+ result.put("postcolor", ColorPickerPreference.convertToARGB(aAppPrefs.postFontColor));
+ result.put("backgroundcolor",
+ ColorPickerPreference.convertToARGB(aAppPrefs.postBackgroundColor));
+ result.put("linkQuoteColor",
+ ColorPickerPreference.convertToARGB(aAppPrefs.postLinkQuoteColor));
+ result.put("highlightUserQuote", Boolean.toString(aAppPrefs.highlightUserQuote));
+ result.put("highlightUsername", Boolean.toString(aAppPrefs.highlightUsername));
+ result.put("postjumpid", mPostJump);
+ } catch (JSONException e) {
+ }
+
+ return result.toString();
+ }
+
+ private class ClickInterface {
+ public static final int QUOTE = 0;
+ public static final int LAST_READ = 1;
+ public static final int EDIT = 2;
+
+ final CharSequence[] mEditablePostItems = { "Quote", "Mark last read", "Edit Post" };
+ final CharSequence[] mPostItems = { "Quote", "Mark last read", "Send Private Message" };
+
+ // Post ID is the item tapped
+ public void onPostClick(final String aPostId, final String aLastReadUrl,
+ final String aUsername) {
+ new AlertDialog.Builder(getActivity()).setTitle("Select an Action")
+ .setItems(mPostItems, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface aDialog, int aItem) {
+ onPostActionItemSelected(aItem, aPostId, aLastReadUrl, aUsername);
+ }
+ }).show();
+ }
+
+ // Post ID is the item tapped
+ public void onEditablePostClick(final String aPostId, final String aLastReadUrl) {
+ new AlertDialog.Builder(getActivity()).setTitle("Select an Action")
+ .setItems(mEditablePostItems, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface aDialog, int aItem) {
+ onPostActionItemSelected(aItem, aPostId, aLastReadUrl, null);
+ }
+ }).show();
+ }
+
+ public void onPreviousPageClick() {
+ getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ goToPage(mAdapter.getPage() - 1);
+ }
+ });
+ }
+
+ public void onNextPageClick() {
+ getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ goToPage(mAdapter.getPage() + 1);
+ }
+ });
+ }
+
+ public void onRefreshPageClick() {
+ getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ refresh();
+ }
+ });
+ }
+ }
@Override
public void onServiceConnected() {
// TODO Auto-generated method stub
-
+
}
@Override
public void onPreferenceChange(AwfulPreferences mPrefs) {
// don't need this, threadview is automatically refreshed on resume.
-
+
}
public void setPostJump(String postID) {
mPostJump = postID;
}
-
- public void goToPage(int aPage){
+
+ public void goToPage(int aPage) {
mAdapter.goToPage(aPage);
mPageCountText.setText("Page " + mAdapter.getPage() + "/" + mAdapter.getLastPage());
mPostJump = "";
View
2  src/com/ferg/awful/constants/Constants.java
@@ -43,6 +43,7 @@
public static final String FUNCTION_SEARCH = BASE_URL + "/search.php";
public static final String FUNCTION_PRIVATE_MESSAGE = BASE_URL + "/private.php";
public static final String FUNCTION_BANLIST = BASE_URL + "/banlist.php";
+ public static final String FUNCTION_RATE_THREAD = BASE_URL + "/threadrate.php";
public static final String ACTION_PROFILE = "getinfo";
public static final String ACTION_SEARCH_POST_HISTORY = "do_search_posthistory";
@@ -60,6 +61,7 @@
public static final String PARAM_INDEX = "index";
public static final String PARAM_BOOKMARK = "bookmark";
public static final String PARAM_PRIVATE_MESSAGE_ID = "privatemessageid";
+ public static final String PARAM_VOTE = "vote";
public static final String FRAGMENT_PTI = "pti";
Please sign in to comment.
Something went wrong with that request. Please try again.