Android Open Source - StreamHub-Android-Reviews-App Reply






From Project

Back to project page StreamHub-Android-Reviews-App.

License

The source code is released under:

MIT License

If you think the Android project StreamHub-Android-Reviews-App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package livefyre.activities;
/* www.j  a  va 2 s  .  com*/
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.livefyre.R;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.json.JSONException;
import org.json.JSONObject;

import java.net.MalformedURLException;
import java.util.HashMap;

import livefyre.BaseActivity;
import livefyre.LFSAppConstants;
import livefyre.LFSConfig;
import livefyre.LFUtils;
import livefyre.models.ContentBean;
import livefyre.parsers.ContentParser;
import livefyre.streamhub.LFSActions;
import livefyre.streamhub.LFSConstants;
import livefyre.streamhub.WriteClient;

public class Reply extends BaseActivity {

  Button postReply, backtoReviewInDetailActivity;
  EditText newReplyEt;
  String id, replytext;
  Boolean isEdit;
  ContentBean selectedReview;
  TextView replyText;

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.reply);
    init();
    newReplyEt.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        newReplyEt.setCursorVisible(true);
      }
    });
    getDataFromIntent();
    if (isEdit)
      setData();
  }

  private void setData() {
    selectedReview = ContentParser.ContentCollection.get(id);
    newReplyEt.setText(LFUtils.trimTrailingWhitespace(Html
                        .fromHtml(selectedReview.getBodyHtml())),
        TextView.BufferType.SPANNABLE);
  }

  void init() {
    newReplyEt = (EditText) findViewById(R.id.newReplyEt);
    postReply = (Button) findViewById(R.id.postReply);
    postReply.setOnClickListener(postReplyListener);
    backtoReviewInDetailActivity = (Button) findViewById(R.id.backtoReviewInDetailActivity);
    backtoReviewInDetailActivity
        .setOnClickListener(backtoReviewInDetailActivityListener);

    replyText = (TextView) findViewById(R.id.replyText);
    replyText.setOnClickListener(backtoReviewInDetailActivityListener);
    if (!isNetworkAvailable()) {
      showToast("Network Not Available");
      return;
    }
  }

  void getDataFromIntent() {
    Intent fromInDetailAdapter = getIntent();
    id = fromInDetailAdapter.getStringExtra("id");
    isEdit = fromInDetailAdapter.getBooleanExtra("isEdit", false);
  }

  OnClickListener backtoReviewInDetailActivityListener = new OnClickListener() {

    public void onClick(View v) {
      Intent returnIntent = new Intent();
      setResult(RESULT_CANCELED, returnIntent);
      finish(); 
    }
  };

  OnClickListener postReplyListener = new OnClickListener() {

    public void onClick(View v) {
      if (!isNetworkAvailable()) {
        showToast("Network Not Available");
        return;
      }
      replytext = newReplyEt.getText().toString();
      if (replytext.length() != 0) {
        String htmlReplytext = Html.toHtml(newReplyEt.getText());
        Log.d("htmlReplytext", htmlReplytext);
        postNewReply(htmlReplytext);
      } else {
        showAlert("Please enter text before post.",
            LFSAppConstants.DISMISS);
      }
    }
  };

  void postNewReply(String body) {
    showProgress();

    if (!isEdit) {
      Log.d("REPLY", "IN NEW REPLY");
      HashMap<String, Object> parameters = new HashMap();
      parameters.put(LFSConstants.LFSPostBodyKey, body);
      parameters.put(LFSConstants.LFSPostType,
          LFSConstants.LFSPostTypeReply);
      parameters.put(LFSConstants.LFSPostUserTokenKey,
          LFSConfig.USER_TOKEN);
      try {
        WriteClient.postContent(LFSConfig.NETWORK_ID,
            LFSConfig.COLLECTION_ID, id, LFSConfig.USER_TOKEN,
            parameters, new newReplyCallback());
      } catch (MalformedURLException e) {
        e.printStackTrace();
      }
    } else {
      Log.d("EDIT", "IN EDIT REPLY");

      RequestParams parameters = new RequestParams();
      parameters.put(LFSConstants.LFSPostBodyKey, body);
      parameters.put(LFSConstants.LFSPostUserTokenKey,
          LFSConfig.USER_TOKEN);
      WriteClient.postAction(LFSConfig.COLLECTION_ID, id,
          LFSConfig.USER_TOKEN, LFSActions.EDIT, parameters,
          new editCallback());

    }
  }

  private class editCallback extends JsonHttpResponseHandler {

    public void onSuccess(JSONObject data) {
      dismissProgress();
      showAlert("Reply Edited Successfully.", LFSAppConstants.FINISH);
      // Log.d("Log", "" + data);
      // showToast("Reply Edited Successfully.");
    }

    @Override
    public void onFailure(Throwable error, String content) {
      super.onFailure(error, content);
      dismissProgress();
      try {
        JSONObject errorJson=new JSONObject(content);
        if(!errorJson.isNull("msg")){
          showAlert(errorJson.getString("msg"), LFSAppConstants.DISMISS);

        }else{
          showAlert("Something went wrong.", LFSAppConstants.DISMISS);
        }
      } catch (JSONException e) {
        e.printStackTrace();
        showAlert("Something went wrong.", LFSAppConstants.DISMISS);

      }
    }

  }

  public class newReplyCallback extends JsonHttpResponseHandler {

    public void onSuccess(JSONObject data) {
      dismissProgress();
      showAlert("Reply Posted Successfully.", LFSAppConstants.FINISH);
      Intent returnIntent = new Intent();
      returnIntent.putExtra("result",1); 
      setResult(RESULT_OK,returnIntent);
    }

    @Override
    public void onFailure(Throwable error, String content) {
      super.onFailure(error, content);
      dismissProgress();
      try {
        JSONObject errorJson=new JSONObject(content);
        if(!errorJson.isNull("msg")){
          showAlert(errorJson.getString("msg"), LFSAppConstants.DISMISS);

        }else{
          showAlert("Something went wrong.", LFSAppConstants.DISMISS);
        }
      } catch (JSONException e) {
        e.printStackTrace();
        showAlert("Something went wrong.", LFSAppConstants.DISMISS);

      }
    }

  }

}




Java Source Code List

com.filepicker.sdk.AuthActivity.java
com.filepicker.sdk.AuthError.java
com.filepicker.sdk.BuildConfig.java
com.filepicker.sdk.BuildConfig.java
com.filepicker.sdk.CacheElement.java
com.filepicker.sdk.DataCache.java
com.filepicker.sdk.FPFile.java
com.filepicker.sdk.FPService.java
com.filepicker.sdk.FilePickerAPI.java
com.filepicker.sdk.FilePicker.java
com.filepicker.sdk.FixedSizeList.java
com.filepicker.sdk.Folder.java
com.filepicker.sdk.Inode.java
com.filepicker.sdk.NonThumbnailGridBlockView.java
com.filepicker.sdk.Service.java
com.filepicker.sdk.ThumbnailView.java
livefyre.AppSingleton.java
livefyre.BaseActivity.java
livefyre.DeviceNotConnectedException.java
livefyre.DownloadAllImagesTask.java
livefyre.LFSAppConstants.java
livefyre.LFSConfig.java
livefyre.LFUtils.java
livefyre.LivefyreApplication.java
livefyre.NotifyingScrollView.java
livefyre.ImagesCache.DownloadImageTask.java
livefyre.ImagesCache.ImagesCache.java
livefyre.activities.Edit.java
livefyre.activities.LivefyreSplash.java
livefyre.activities.NewReview.java
livefyre.activities.Reply.java
livefyre.activities.ReviewInDetail.java
livefyre.activities.ReviewsActivity.java
livefyre.adapters.ReviewInDetailAdapter.java
livefyre.adapters.ReviewListAdapter.java
livefyre.fadingactionbar.FadingActionBarHelperBase.java
livefyre.fadingactionbar.FadingActionBarHelper.java
livefyre.fadingactionbar.ListViewActivity.java
livefyre.fadingactionbar.ObservableScrollView.java
livefyre.fadingactionbar.ObservableScrollable.java
livefyre.fadingactionbar.ObservableWebViewWithHeader.java
livefyre.fadingactionbar.OnScrollChangedCallback.java
livefyre.fadingactionbar.RootLayout.java
livefyre.fadingactionbar.Utils.java
livefyre.models.AuthorsBean.java
livefyre.models.ContentBean.java
livefyre.models.ContentTypeEnum.java
livefyre.models.OembedBean.java
livefyre.models.ReviewStatus.java
livefyre.models.Vote.java
livefyre.parsers.AdminClintParser.java
livefyre.parsers.ContentParser.java
livefyre.parsers.ContentUpdateListener.java
livefyre.streamhub.AdminClient.java
livefyre.streamhub.BootstrapClient.java
livefyre.streamhub.BuildConfig.java
livefyre.streamhub.BuildConfig.java
livefyre.streamhub.Config.java
livefyre.streamhub.Helpers.java
livefyre.streamhub.HttpClient.java
livefyre.streamhub.LFSActions.java
livefyre.streamhub.LFSConstants.java
livefyre.streamhub.LFSFlag.java
livefyre.streamhub.StreamClient.java
livefyre.streamhub.WriteClient.java