package com.woxthebox.draglistview.sample.publish;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.woxthebox.draglistview.DragListView;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class PublishNormalTopicAct extends Activity {
private TextView tvSelectBangName;
private View rlSelectBang;
private EmojiEditText etTopicTitle;
protected TextView mSendTv; // 发布
//可拖动的view
private DragListView mDragListView;
/***发帖实体类*/
private TopicPublishModelNew modelNew = new TopicPublishModelNew();
private PublishTopicAdapter publishAdapter;
private LinearLayout llTitleParent;
/****拖动浮动的view*/
private PublishDragView dragFloatView;
private ScrollableLayout scrollableLayout;
protected boolean saveDraf = false;
private String mFromBangId = "";
/***监听布局变化,用于监听键盘变化*/
private ViewTreeObserver.OnGlobalLayoutListener mKeyboardChangeListener;
/***
* @param context
* @param bid
* @param title
* @param default_content
*/
public static void startInstanceGame(Context context, String bid, String title, String default_content)
{
Intent intent = new Intent();
intent.setClass(context, PublishNormalTopicAct.class);
intent.putExtra(PublishTopicKey.EXTRA_BID, bid);
intent.putExtra(PublishTopicKey.EXTRA_TITLE, title);
intent.putExtra(PublishTopicKey.EXTRA_CONTENT_HINT, default_content);
intent.putExtra(PublishTopicKey.EXTRA_IS_HIDE_HELP, true);
intent.putExtra(PublishTopicKey.EXTRA_IS_GAME, true);
intent.putExtra("isFromBangDetail", true); // 添加传递来自帮内发帖,则不打开新帮
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.publish_topic_layout);
// mHandler = new IHandler<>(this);
getArgsIntent();
PublishModelManager.init(modelNew);
showTitleView();
initViews();
getTopicLimit();//获取限制条件完成后,才加载发帖页面
}
private void showTitleView() {
getTitleHeaderBar().setVisibility(View.VISIBLE);
getTitleHeaderBar().setTitle("编辑话题");
mSendTv = getTitleHeaderBar().showRightText("发布");
}
public void getArgsIntent() {//获取参数
Intent intent = getIntent();
if (null != intent) {
if (intent.hasExtra(PublishTopicKey.EXTRA_DRAFT_AND_EDIT)) {//草稿和编辑
TopicPublishModelNew tempModelNew = (TopicPublishModelNew) getIntent().getSerializableExtra(PublishTopicKey.EXTRA_DRAFT_AND_EDIT);
if (null != tempModelNew) {
modelNew = tempModelNew;
if (null == modelNew.contentList) {
modelNew.contentList = new ArrayList<>();
}
}
mIsFromSendTopicTaskView = intent.getIntExtra("source_from", 0) == DraftTableDao.From_Source_Bang;
} else {//正常发帖
modelNew.bid = intent.getStringExtra(PublishTopicKey.EXTRA_BID);
modelNew.is_Hide_Help = intent.getBooleanExtra(PublishTopicKey.EXTRA_IS_HIDE_HELP, false);
String activeTid = intent.getStringExtra(PublishTopicKey.EXTRA_ACTIVE_ID);
boolean isCongraduation = intent.getBooleanExtra(PublishTopicKey.EXTRA_IS_CONGRADUATION, false);
boolean isGame = intent.getBooleanExtra(PublishTopicKey.EXTRA_IS_GAME, false);
String title = intent.getStringExtra(PublishTopicKey.EXTRA_TITLE);
String titleHint = intent.getStringExtra(PublishTopicKey.EXTRA_TITLE_HINT);
String contentHint = intent.getStringExtra(PublishTopicKey.EXTRA_CONTENT_HINT);
String tagIds = intent.getStringExtra(PublishTopicKey.EXTRA_TAGID);
String content = intent.getStringExtra(PublishTopicKey.EXTRA_CONTENT);
if (!ToolString.isEmpty(title)) {
modelNew.title = title;
}
if (!ToolString.isEmpty(titleHint)) {
modelNew.titleHint = titleHint;
}
if (!ToolString.isEmpty(contentHint)) {
modelNew.contentHint = contentHint;
}
if (!ToolString.isEmpty(tagIds)) {
modelNew.new_tags = tagIds;
}
if (!ToolString.isEmpty(content)) {
modelNew.contentList.add(TopicPublishModelNew.TypeContent.createTextInstance(0, content));
}
if (!ToolString.isEmpty(activeTid)) {//活动帖id
modelNew.active_type = 23;
modelNew.active_tid = activeTid;
} else if (isCongraduation) {//报喜帖
modelNew.type = 24;
} else if (isGame) {//晒照帖(游戏帖)
modelNew.type = 109;
}
}
mFromBangId = modelNew.bid;
modelNew.source_from = intent.getIntExtra("source_from", 0);
if (modelNew.active_type == 23) {// 活动贴,上报埋点为4
ToolCollecteData.collectStringData(this, AnalyticsEvent.EventIDs.TIEDITTO, " | | |4| ");
} else if (modelNew.type == 24 || modelNew.source_from == 3) {// 报喜帖上报埋点为“3”
ToolCollecteData.collectStringData(this, AnalyticsEvent.EventIDs.TIEDITTO, " | | |3| ");
} else if (modelNew.source_from == 1) {// 首页发帖上报埋点为“2”
ToolCollecteData.collectStringData(this, AnalyticsEvent.EventIDs.TIEDITTO, " | | |2| ");
} else if (modelNew.source_from == 2) {// 帮内发帖上报埋点为“1”
ToolCollecteData.collectStringData(this, AnalyticsEvent.EventIDs.TIEDITTO, " | | |1| ");
}
}
}
private void initData() {
setTitleHeight();
String title = etTopicTitle.getText().toString();
if (!ToolString.isEmpty(title)) {//防止弱网请求未返回,输入标题,此时还未设置监听器,导致发布不高亮显示
modelNew.title = title;
}
if (ToolOthers.isListEmpty(modelNew.contentList)) {//限制条件请求完成后才显示第一行
modelNew.contentList.add(TopicPublishModelNew.TypeContent.createTextInstance(0, ""));
} else {//草稿或编辑
publishAdapter.resetList(modelNew.contentList);
}
publishAdapter.setItemList(modelNew.contentList);
if (null != PublicData.topic_tips) {
etTopicTitle.setHint(PublicData.topic_tips.add_topic_title);
}
if (!ToolString.isEmpty(modelNew.title)) {
etTopicTitle.setText(modelNew.title);
}
if (1 == modelNew.is_edit) {//是编辑帖子 帮�