|
@@ -1,7 +1,9 @@
|
|
|
package org.telegram.cricdit.ui;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
import android.graphics.drawable.GradientDrawable;
|
|
|
import android.os.Build;
|
|
|
+import android.os.Vibrator;
|
|
|
import android.text.Editable;
|
|
|
import android.text.InputType;
|
|
|
import android.text.TextUtils;
|
|
@@ -9,6 +11,7 @@ import android.text.TextWatcher;
|
|
|
import android.util.TypedValue;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
|
+import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
@@ -33,6 +36,7 @@ import org.telegram.cricdit.bean.RankVoteEvent;
|
|
|
import org.telegram.cricdit.config.Config;
|
|
|
import org.telegram.cricdit.mvp.PublishRankingPresenter;
|
|
|
import org.telegram.cricdit.mvp.PublishRankingView;
|
|
|
+import org.telegram.cricdit.net.ApiException;
|
|
|
import org.telegram.cricdit.utils.ColorUtil;
|
|
|
import org.telegram.cricdit.utils.EventBusHelper;
|
|
|
import org.telegram.cricdit.utils.ToastUtil;
|
|
@@ -40,11 +44,13 @@ import org.telegram.cricdit.utils.UIUtil;
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
import org.telegram.messenger.R;
|
|
|
+import org.telegram.messenger.UserConfig;
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
import org.telegram.ui.Components.EditTextBoldCursor;
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
+import org.telegram.ui.Components.NumberTextView;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -52,15 +58,18 @@ import java.util.List;
|
|
|
public class PublishRankingActivity extends BaseActivity<PublishRankingPresenter> implements PublishRankingView {
|
|
|
|
|
|
private RecyclerView mRecyclerView;
|
|
|
+ private View view;
|
|
|
// private EditTextBoldCursor firstNameField;
|
|
|
// private FrameLayout mHeadContainer;
|
|
|
private PublishRankingAdapter mAdapter;
|
|
|
private List<PublishRankBean> mPublishRankBeanList;
|
|
|
private EditText et_title;
|
|
|
- private TextView tv_title_length;
|
|
|
+ private NumberTextView tv_title_length;
|
|
|
private TextView tv_2;
|
|
|
private View view_add;
|
|
|
+ private LinearLayout ll_title;
|
|
|
private ActionBarMenuItem actionBarMenuItem;
|
|
|
+ private final int maxTitleLength = 50;
|
|
|
@Override
|
|
|
protected int getLayoutResId() {
|
|
|
return R.layout.activity_publish_ranking;
|
|
@@ -78,17 +87,32 @@ public class PublishRankingActivity extends BaseActivity<PublishRankingPresenter
|
|
|
|
|
|
@Override
|
|
|
protected void initView(View view) {
|
|
|
+ this.view = view;
|
|
|
mRecyclerView = view.findViewById(R.id.publish_ranking_recyclerview);
|
|
|
et_title = view.findViewById(R.id.et_title);
|
|
|
- tv_title_length = view.findViewById(R.id.tv_title_length);
|
|
|
tv_2 = view.findViewById(R.id.tv_2);
|
|
|
view_add = view.findViewById(R.id.view_add);
|
|
|
-
|
|
|
+ ll_title = view.findViewById(R.id.ll_title);
|
|
|
+
|
|
|
+ tv_title_length = new NumberTextView(getContext());
|
|
|
+ tv_title_length.setCenterAlign(true);
|
|
|
+ tv_title_length.setTextSize(15);
|
|
|
+ tv_title_length.setNumber(maxTitleLength, false);
|
|
|
+ tv_title_length.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
|
|
|
+ tv_title_length.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
|
|
+ ll_title.addView(tv_title_length, LayoutHelper.createFrame(26, 20, LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT, 0, 0, 0, 0));
|
|
|
+ et_title.setHorizontallyScrolling(false);
|
|
|
EventBusHelper.register(this);
|
|
|
|
|
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
|
mPublishRankBeanList = new ArrayList<>();
|
|
|
mAdapter = new PublishRankingAdapter(getContext(),R.layout.item_publish_rank, mPublishRankBeanList);
|
|
|
+ View inflate = LayoutInflater.from(getContext()).inflate(R.layout.layout_empty_view, null, false);
|
|
|
+ inflate.setPadding(0,UIUtil.dip2px(getContext(),50),0,0);
|
|
|
+
|
|
|
+ TextView tvTip = inflate.findViewById(R.id.empty_view_title);
|
|
|
+ tvTip.setText(LocaleController.getString(R.string.no_options));
|
|
|
+ mAdapter.setEmptyView(inflate);
|
|
|
mRecyclerView.setAdapter(mAdapter);
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
@@ -98,11 +122,6 @@ public class PublishRankingActivity extends BaseActivity<PublishRankingPresenter
|
|
|
}
|
|
|
|
|
|
initListener();
|
|
|
-
|
|
|
-/* View inflate = LayoutInflater.from(getContext()).inflate(R.layout.head_publish_rank, null, false);
|
|
|
- mHeadContainer = inflate.findViewById(R.id.head_publish_ranking_container);
|
|
|
- initEdit();
|
|
|
- mAdapter.addHeaderView(inflate);*/
|
|
|
}
|
|
|
|
|
|
private void initListener(){
|
|
@@ -117,9 +136,10 @@ public class PublishRankingActivity extends BaseActivity<PublishRankingPresenter
|
|
|
return;
|
|
|
}
|
|
|
if(mPublishRankBeanList.size() > 1){
|
|
|
- //fixme ltt 请求接口,发布排行榜
|
|
|
- ToastUtil.show(getContext(),LocaleController.getString(R.string.publish_success));
|
|
|
- finishFragment();
|
|
|
+ AndroidUtilities.hideKeyboard(et_title);
|
|
|
+ if (UserConfig.getInstance(UserConfig.selectedAccount).isClientActivated()) {
|
|
|
+ presenter.publishRanking(title,mPublishRankBeanList);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -133,21 +153,35 @@ public class PublishRankingActivity extends BaseActivity<PublishRankingPresenter
|
|
|
|
|
|
et_title.addTextChangedListener(new TextWatcher() {
|
|
|
@Override
|
|
|
- public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
-
|
|
|
- }
|
|
|
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
|
|
|
|
|
@Override
|
|
|
- public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
-
|
|
|
+ public void onTextChanged(CharSequence s, int i, int i1, int i2) {
|
|
|
+ int remainLength = maxTitleLength - Character.codePointCount(s, 0, s.length());
|
|
|
+ if(remainLength < 0){
|
|
|
+ et_title.setText(s.subSequence(0,maxTitleLength));
|
|
|
+ et_title.setSelection(s.subSequence(0,maxTitleLength).length());
|
|
|
+ Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
|
|
+ if (v != null) {
|
|
|
+ v.vibrate(200);
|
|
|
+ }
|
|
|
+ AndroidUtilities.shakeView(tv_title_length, 2, 0);
|
|
|
+ }else{
|
|
|
+ tv_title_length.setNumber(remainLength,true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void afterTextChanged(Editable editable) {
|
|
|
- tv_title_length.setText(editable.length()+"/50");
|
|
|
- //fixme ltt 加晃动动画
|
|
|
+ public void afterTextChanged(Editable s) {}
|
|
|
+ });
|
|
|
|
|
|
+ et_title.setOnEditorActionListener((v, actionId, event) -> {
|
|
|
+ if(actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_UNSPECIFIED){
|
|
|
+ et_title.clearFocus();
|
|
|
+ AndroidUtilities.hideKeyboard(et_title);
|
|
|
+ return true;
|
|
|
}
|
|
|
+ return false;
|
|
|
});
|
|
|
|
|
|
}
|
|
@@ -168,10 +202,8 @@ public class PublishRankingActivity extends BaseActivity<PublishRankingPresenter
|
|
|
//<2条时隐藏发布按钮,>9条隐藏添加按钮
|
|
|
if(mPublishRankBeanList.size() > 1){
|
|
|
actionBarMenuItem.setVisibility(View.VISIBLE);
|
|
|
- tv_2.setVisibility(View.VISIBLE);
|
|
|
}else{
|
|
|
actionBarMenuItem.setVisibility(View.GONE);
|
|
|
- tv_2.setVisibility(View.GONE);
|
|
|
}
|
|
|
actionBarMenuItem.setVisibility(mPublishRankBeanList.size() > 1 ? View.VISIBLE : View.GONE);
|
|
|
view_add.setVisibility(mPublishRankBeanList.size() >9 ? View.GONE : View.VISIBLE);
|
|
@@ -183,37 +215,26 @@ public class PublishRankingActivity extends BaseActivity<PublishRankingPresenter
|
|
|
EventBusHelper.unregister(this);
|
|
|
}
|
|
|
|
|
|
- private void initEdit() {
|
|
|
-/*
|
|
|
- firstNameField = new EditTextBoldCursor(getContext());
|
|
|
- firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
- firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
|
|
|
- firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
- firstNameField.setBackgroundDrawable(null);
|
|
|
- firstNameField.setLineColors(getThemedColor(Theme.key_windowBackgroundWhiteInputField), getThemedColor(Theme.key_windowBackgroundWhiteInputFieldActivated), getThemedColor(Theme.key_windowBackgroundWhiteRedText3));
|
|
|
- firstNameField.setMaxLines(1);
|
|
|
- firstNameField.setLines(1);
|
|
|
- firstNameField.setPadding(0, 0, 0, 0);
|
|
|
- firstNameField.setSingleLine(true);
|
|
|
- firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
|
|
|
- firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
|
|
|
- firstNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
|
|
- firstNameField.setHint(LocaleController.getString("UsernamePlaceholder", R.string.UsernamePlaceholder));
|
|
|
- firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
- firstNameField.setCursorSize(AndroidUtilities.dp(20));
|
|
|
- firstNameField.setCursorWidth(1.5f);
|
|
|
- mHeadContainer.addView(firstNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));
|
|
|
-*/
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ view.requestLayout();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void showSuccess(String url) {
|
|
|
- //pass
|
|
|
+ public void showSuccess(String info) {
|
|
|
+ ToastUtil.show(getContext(),info);
|
|
|
+ finishFragment();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void showError(Throwable e) {
|
|
|
- //pass
|
|
|
+ if (!(e instanceof ApiException)) {
|
|
|
+ ToastUtil.show(getContext(),LocaleController.getString(R.string.network_failed));
|
|
|
+ } else {
|
|
|
+ ToastUtil.show(getContext(),e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|