package com.ysvideo.zhibo.app.ui.video;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
import android.graphics.drawable.ColorDrawable;
|
import android.os.Handler;
|
import android.view.Gravity;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.View.OnFocusChangeListener;
|
import android.view.ViewGroup.LayoutParams;
|
import android.view.WindowManager;
|
import android.view.inputmethod.InputMethodManager;
|
import android.widget.Button;
|
import android.widget.EditText;
|
import android.widget.PopupWindow;
|
import android.widget.Toast;
|
|
import com.ysvideo.zhibo.app.R;
|
import com.ysvideo.zhibo.app.util.LoginUtil;
|
import com.ysvideo.zhibo.lib.common.util.common.StringUtils;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
public class VideoReviewPopupWindow extends PopupWindow {
|
private LayoutInflater mInflater;
|
private View conentView;
|
private EditText tv_review_edit;
|
private Button tv_review_deliver;
|
private FragmentActivity mContext;
|
private String videoId;// 影片ID
|
private String thirdType;// 影片类型分辨
|
private boolean reviewFlag;// true为评论 false为回复
|
private String editHint;// hint文字
|
|
public VideoReviewPopupWindow(final FragmentActivity context,
|
String videoId, String thirdType, final boolean reviewFlag,
|
String editHint) {
|
mContext = context;
|
this.videoId = videoId;
|
this.thirdType = thirdType;
|
this.reviewFlag = reviewFlag;
|
mInflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
SharedPreferences preferences = context.getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
isLogin = !StringUtils.isEmpty(preferences.getString("LoginUid", ""));
|
conentView = mInflater.inflate(R.layout.popupwindow_video_review, null);
|
this.setContentView(conentView);
|
|
this.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
|
// 软键盘不会挡着popupwindow
|
this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
this.setWidth(LayoutParams.MATCH_PARENT);
|
this.setHeight(LayoutParams.WRAP_CONTENT);
|
|
this.setFocusable(true);
|
this.setOutsideTouchable(false);
|
ColorDrawable dw = new ColorDrawable(0000000000);
|
this.setBackgroundDrawable(dw);
|
this.update();
|
|
tv_review_edit = conentView
|
.findViewById(R.id.tv_review_edit);
|
tv_review_deliver = conentView
|
.findViewById(R.id.tv_review_deliver);
|
|
if (!StringUtils.isBlank(editHint)) {
|
tv_review_edit.setHint(editHint);
|
}
|
|
tv_review_deliver.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
|
if (isLogin) {
|
if (!StringUtils.isBlank(tv_review_edit.getEditableText()
|
.toString())) {
|
|
} else {
|
Toast.makeText(mContext, "请输入内容", Toast.LENGTH_SHORT)
|
.show();
|
}
|
} else {
|
setLogin();
|
}
|
dismiss();
|
}
|
});
|
|
tv_review_edit.setOnFocusChangeListener(new OnFocusChangeListener() {
|
|
@Override
|
public void onFocusChange(View v, boolean hasFocus) {
|
if (hasFocus) {
|
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
}
|
}
|
});
|
|
}
|
|
/**
|
* 显示popupWindow
|
*
|
* @param parent
|
*/
|
public void showPopupWindow(View parent) {
|
if (!this.isShowing()) {
|
// this.showAsDropDown(parent, 0, 0, Gravity.BOTTOM);
|
this.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
|
openKeyboard(new Handler(), 200);
|
} else {
|
this.dismiss();
|
}
|
}
|
|
/**
|
* 打开软键盘
|
*/
|
private void openKeyboard(Handler mHandler, int s) {
|
mHandler.postDelayed(new Runnable() {
|
@Override
|
public void run() {
|
InputMethodManager imm = (InputMethodManager) mContext
|
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
|
}
|
}, s);
|
}
|
|
/**
|
* 发布评论还是登录
|
*/
|
private boolean isLogin = false;// false为未登录,true为已经为登录状态
|
|
/**
|
* 登录
|
*/
|
private void setLogin() {
|
LoginUtil.goLogin(mContext);
|
}
|
|
|
}
|