Android Open Source - StreamHub-Android-Reviews-App Edit






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;
//from www  .j ava 2 s .  c o  m
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
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.RatingBar;
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 livefyre.AppSingleton;
import livefyre.BaseActivity;
import livefyre.LFSAppConstants;
import livefyre.LFSConfig;
import livefyre.LFUtils;
import livefyre.LivefyreApplication;
import livefyre.models.ContentBean;
import livefyre.parsers.ContentParser;
import livefyre.streamhub.LFSActions;
import livefyre.streamhub.LFSConstants;
import livefyre.streamhub.WriteClient;


public class Edit extends BaseActivity {

  EditText editReviewTitleEt, editReviewBodyEt;
  Button editPostReview, backtoReviewInDetailFromEditActivity;
  RatingBar editReviewRatingBar;
  TextView editReviewTitleTv, editReviewBodyTv, editReviewText;
  String id, title, body;
  ContentBean selectedReview;
  int rating;
  private LivefyreApplication application;

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.edit);

    init();
    editReviewTitleEt.setOnClickListener(new OnClickListener() {

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

    editReviewTitleEt.addTextChangedListener(new TextWatcher() {
      @Override
      public void onTextChanged(CharSequence s, int start, int before,
          int count) {
      }

      @Override
      public void beforeTextChanged(CharSequence s, int start, int count,
          int after) {

        if (editReviewTitleEt.getText().toString().length() > 0) {
          editReviewTitleTv.setVisibility(View.VISIBLE);
          editReviewTitleEt.setHintTextColor(Color
              .parseColor("#ffffff"));
        } else {
          editReviewTitleTv.setVisibility(View.INVISIBLE);
          editReviewTitleEt.setHintTextColor(Color
              .parseColor("#cdcdcd"));
        }
      }

      @Override
      public void afterTextChanged(Editable s) {

        if (editReviewTitleEt.getText().toString().length() > 0) {
          editReviewTitleTv.setVisibility(View.VISIBLE);
          editReviewTitleEt.setHintTextColor(Color
              .parseColor("#ffffff"));
        } else {
          editReviewTitleTv.setVisibility(View.INVISIBLE);
          editReviewTitleEt.setHintTextColor(Color
              .parseColor("#cdcdcd"));
        }
      }
    });

    editReviewBodyEt.addTextChangedListener(new TextWatcher() {
      @Override
      public void onTextChanged(CharSequence s, int start, int before,
          int count) {
      }

      @Override
      public void beforeTextChanged(CharSequence s, int start, int count,
          int after) {

        if (editReviewBodyEt.getText().toString().length() > 0) {
          editReviewBodyTv.setVisibility(View.VISIBLE);
          editReviewBodyEt.setHintTextColor(Color
              .parseColor("#ffffff"));
        } else {
          editReviewBodyTv.setVisibility(View.INVISIBLE);
          editReviewBodyEt.setHintTextColor(Color
              .parseColor("#cdcdcd"));
        }
      }

      @Override
      public void afterTextChanged(Editable s) {

        if (editReviewBodyEt.getText().toString().length() > 0) {
          editReviewBodyTv.setVisibility(View.VISIBLE);
          editReviewBodyEt.setHintTextColor(Color
              .parseColor("#ffffff"));
        } else {
          editReviewBodyTv.setVisibility(View.INVISIBLE);
          editReviewBodyEt.setHintTextColor(Color
              .parseColor("#cdcdcd"));
        }
      }
    });

  }

  void init() {

    application = AppSingleton.getInstance().getApplication();

    editReviewTitleTv = (TextView) findViewById(R.id.editReviewTitleTv);
    editReviewBodyTv = (TextView) findViewById(R.id.editReviewBodyTv);
    editReviewText = (TextView) findViewById(R.id.editReviewText);
    editReviewText
        .setOnClickListener(backtoReviewInDetailFromEditActivityListener);

    editReviewTitleEt = (EditText) findViewById(R.id.editReviewTitleEt);
    editReviewBodyEt = (EditText) findViewById(R.id.editReviewBodyEt);

    editPostReview = (Button) findViewById(R.id.editPostReview);
    editPostReview.setOnClickListener(editPostReplyListener);

    editReviewRatingBar = (RatingBar) findViewById(R.id.editReviewRatingBar);

    backtoReviewInDetailFromEditActivity = (Button) findViewById(R.id.backtoReviewInDetailFromEditActivity);
    backtoReviewInDetailFromEditActivity
        .setOnClickListener(backtoReviewInDetailFromEditActivityListener);
    if (!isNetworkAvailable()) {
      showToast("Network Not Available");
      return;
    }
  }

  void getDataFromIntent() {
    Intent fromInDetailAdapter = getIntent();
    id = fromInDetailAdapter.getStringExtra("id");
  }

  void setData() {
    selectedReview = ContentParser.ContentCollection.get(id);
    editReviewTitleEt.setText(selectedReview.getTitle());
    editReviewBodyEt.setText(LFUtils.trimTrailingWhitespace(Html
                        .fromHtml(selectedReview.getBodyHtml())),
        TextView.BufferType.SPANNABLE);

    editReviewRatingBar.setRating(Float.parseFloat(selectedReview
        .getRating()) / 20);
    editReviewTitleTv.setVisibility(View.VISIBLE);
    editReviewBodyTv.setVisibility(View.VISIBLE);
    if (selectedReview.getAuthorId().equals(
        application.getDataFromSharedPreferences(LFSAppConstants.ID))) {
      editReviewRatingBar.setIsIndicator(false);
    } else {
      editReviewRatingBar.setIsIndicator(true);
    }

  }

  OnClickListener backtoReviewInDetailFromEditActivityListener = new OnClickListener() {

    public void onClick(View v) {
      finish();
    }
  };

  OnClickListener editPostReplyListener = new OnClickListener() {

    public void onClick(View v) {
      if (!isNetworkAvailable()) {
        showToast("Network Not Available");
        return;
      }
      showProgress();
      title = editReviewTitleEt.getText().toString();
      body = editReviewBodyEt.getText().toString();
      rating = (int) (editReviewRatingBar.getRating() * 20);

      if (title.length() == 0) {
        showAlert("Please enter title before post.",
            LFSAppConstants.DISMISS);
        return;
      }
      if (body.length() == 0) {
        showAlert("Please enter description before post.",
            LFSAppConstants.DISMISS);
        return;
      }
      if (rating == 0) {
        showAlert("Please give rating before post.",
            LFSAppConstants.DISMISS);
        return;
      }
      String htmlBody = Html.toHtml(editReviewBodyEt.getText());
      RequestParams parameters = new RequestParams();
      parameters.put(LFSConstants.LFSPostBodyKey, htmlBody);
      parameters.put(LFSConstants.LFSPostTitleKey, editReviewTitleEt
          .getText().toString());

      parameters.put(LFSConstants.LFSPostType,
          LFSConstants.LFSPostTypeReview);
      JSONObject ratingJson = new JSONObject();
      try {
        ratingJson.put("default", rating + "");
        parameters.put(LFSConstants.LFSPostRatingKey,
            ratingJson.toString());

      } catch (JSONException e) {
        e.printStackTrace();
      }

      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) {
      Log.d("Log", "" + data);
      dismissProgress();

      showAlert("Review Edited Successfully.", LFSAppConstants.FINISH);
    }

    @Override
    public void onFailure(Throwable error, String content) {
      super.onFailure(error, content);
      dismissProgress();

      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