From 9c7b29c63bdc1261e0097edb77ee83667c0d2f07 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sun, 29 Mar 2020 09:15:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BF=E5=AE=A2=E9=A2=84?= =?UTF-8?q?=E7=BA=A6=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/ui/forum/ShowWordCount.java | 69 ++++++++++++++++++ .../forum/post/ForumPostComplainFragment.java | 35 ++++++++-- .../main/ui/forum/post/ForumPostContent.java | 62 ++-------------- .../visitor/VisitorAppointmentFragment.java | 70 +++++++++++++++++-- .../forum/layout/forum_hot_fragment.xml | 6 +- .../layout/forum_post_complain_fragment.xml | 34 +++------ .../forum/layout/forum_post_content.xml | 2 +- .../res/layout/main/layout/info_fragment.xml | 4 +- .../layout/visitor_appointment_fragment.xml | 70 ++++++++++++++++++- app/src/main/res/values-en-rUS/dimens.xml | 2 + app/src/main/res/values-en-rUS/strings.xml | 4 ++ app/src/main/res/values-zh-rCN/dimens.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 4 ++ app/src/main/res/values/dimens.xml | 2 + app/src/main/res/values/strings.xml | 4 ++ 15 files changed, 270 insertions(+), 100 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java new file mode 100644 index 0000000..5c8f5f7 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java @@ -0,0 +1,69 @@ +package com.community.pocket.ui.main.ui.forum; + +import android.text.Editable; +import android.text.Html; +import android.text.TextWatcher; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; + +import androidx.annotation.IdRes; + +import com.community.pocket.R; + +/** + * 提示正文输入字数 + */ +public class ShowWordCount { + + @IdRes + private int[] ids; + + private View view; + + private EditText postContent; + + public ShowWordCount(int[] ids, int contentId, View view) { + this.ids = ids; + this.view = view; + this.postContent = view.findViewById(contentId); + } + + /** + * 设置计数 + */ + private void setCount() { + String text = view.getContext().getString(R.string.post_content_count, postContent.length(), view.getContext().getResources().getInteger(R.integer.post_content)); + + for (int id : ids) { + TextView textView = view.findViewById(id); + textView.setText(Html.fromHtml(text)); + } + } + + + /** + * 提示正文字数 + */ + public void showCount() { + + setCount(); + + postContent.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + setCount(); + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java index bec00fd..769b6b6 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java @@ -1,27 +1,30 @@ package com.community.pocket.ui.main.ui.forum.post; +import android.os.Build; +import android.os.Bundle; import android.view.View; +import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; -import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; + import com.community.pocket.R; import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.Event; import org.xutils.view.annotation.ViewInject; +import java.util.Objects; + /** * 投诉贴 */ @ContentView(R.layout.forum_post_complain_fragment) public class ForumPostComplainFragment extends ForumPostContent { - /** - * 显示投诉人 - */ - @ViewInject(R.id.show_name) - private TextView showName; /** * 检索投诉人 @@ -29,6 +32,26 @@ public class ForumPostComplainFragment extends ForumPostContent { @ViewInject(R.id.search_name) private AutoCompleteTextView searchName; + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initSearch(); + } + + /** + * 搜索框 + */ + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + private void initSearch() { + //TODO 设置数据源数组 + String[] arrays = {"abc", "abcde", "aef2", "fff", "asdfa"}; + + // 设置适配器 + ArrayAdapter adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays); + // 将适配器与当前AutoCompleteTextView控件绑定 + searchName.setAdapter(adapter); + } /** * 发帖操作 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java index 504b5f1..25b7cf5 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java @@ -5,12 +5,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.text.Editable; -import android.text.Html; -import android.text.TextWatcher; import android.view.View; -import android.widget.EditText; -import android.widget.TextView; import androidx.annotation.IdRes; import androidx.annotation.NonNull; @@ -21,8 +16,7 @@ import androidx.navigation.Navigation; import com.community.pocket.R; import com.community.pocket.ui.BaseFragment; - -import org.xutils.view.annotation.ViewInject; +import com.community.pocket.ui.main.ui.forum.ShowWordCount; import java.util.Objects; @@ -31,24 +25,6 @@ import java.util.Objects; */ abstract class ForumPostContent extends BaseFragment { - /** - * 发送正文 - */ - @ViewInject(R.id.post_content) - private EditText postContent; - - /** - * 字符记数 - */ - @ViewInject(R.id.show_count) - private TextView showCount; - - /** - * 字符记数 - */ - @ViewInject(R.id.show_count_top) - private TextView showCountTop; - /** * 导航 @@ -68,7 +44,8 @@ abstract class ForumPostContent extends BaseFragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - showCount(); + ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_count, R.id.show_count_top}, R.id.post_content, view); + showWordCount.showCount(); initPostCtrl(); } @@ -91,41 +68,10 @@ abstract class ForumPostContent extends BaseFragment { } } - /** - * 设置计数 - */ - private void setCount() { - String text = getString(R.string.post_content_count, postContent.length(), getResources().getInteger(R.integer.post_content)); - showCount.setText(Html.fromHtml(text)); - showCountTop.setText(Html.fromHtml(text)); - } - /** - * 提示正文字数 + * 导航触发器 */ - private void showCount() { - - setCount(); - - postContent.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - setCount(); - } - - @Override - public void afterTextChanged(Editable s) { - - } - }); - } - private static class MyHandler extends Handler { @RequiresApi(api = Build.VERSION_CODES.KITKAT) diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java index cf705d0..40f310c 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java @@ -1,18 +1,80 @@ package com.community.pocket.ui.main.ui.visitor; +import android.os.Build; +import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; +import android.widget.Spinner; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; + import com.community.pocket.R; -import com.community.pocket.ui.main.TestMainFragment; +import com.community.pocket.ui.BaseFragment; +import com.community.pocket.ui.main.ui.forum.ShowWordCount; import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.Event; +import org.xutils.view.annotation.ViewInject; + +import java.util.Objects; /** * 访客预约界面 */ @ContentView(R.layout.visitor_appointment_fragment) -public class VisitorAppointmentFragment extends TestMainFragment { +public class VisitorAppointmentFragment extends BaseFragment { + + //搜索预约住户 + @ViewInject(R.id.appointment) + private AutoCompleteTextView appointment; + @ViewInject(R.id.choose_time) + private Spinner spinner; + + + @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override - protected int viewId() { - return R.id.text_apppointment; + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_word_top, R.id.show_word_bottom}, R.id.notes, view); + showWordCount.showCount(); + initSearch(); + initChooseTime(); + } + + + /** + * 搜索框 + */ + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + private void initSearch() { + //TODO 设置数据源数组 + String[] arrays = {"abc", "abcde", "aef2", "fff", "asdfa"}; + + // 设置适配器 + ArrayAdapter adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays); + // 将适配器与当前AutoCompleteTextView控件绑定 + appointment.setAdapter(adapter); + } + + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + private void initChooseTime() { + //TODO 设置数据源数组 + String[] arrays = {"abc", "efg", "aef2", "fff", "asdfa"}; + // 设置适配器 + ArrayAdapter adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays); + spinner.setAdapter(adapter); + } + + /** + * 提交预约信息 + */ + @Event(value = R.id.submit) + private void submit(View view) { + Toast.makeText(view.getContext(), R.string.submit_appointment, Toast.LENGTH_SHORT).show(); } } diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml index 282aec5..b8f361e 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_hot_fragment.xml @@ -20,7 +20,7 @@ @@ -42,7 +42,7 @@ @@ -64,7 +64,7 @@ diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_post_complain_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_post_complain_fragment.xml index a64f9b9..d5b26f6 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_post_complain_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_post_complain_fragment.xml @@ -10,41 +10,29 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - - - - - - +