From 9fe5f3415904c5ac20b0a58a47cd85dcd0b039cd Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sat, 28 Mar 2020 22:00:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=91=E8=A1=A8=E5=B8=96?= =?UTF-8?q?=E5=AD=90=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pocket/data/adapter/NoticeAdpter.java | 1 + .../ui/main/ui/forum/ForumPostFragment.java | 19 --- .../forum/post/ForumPostActiveFragment.java | 35 +++++ .../forum/post/ForumPostActiveViewModel.java | 7 + .../forum/post/ForumPostComplainFragment.java | 40 +++++ .../post/ForumPostComplainViewModel.java | 7 + .../main/ui/forum/post/ForumPostContent.java | 147 ++++++++++++++++++ .../main/ui/forum/post/ForumPostFragment.java | 64 ++++++++ .../ui/forum/post/ForumPostTopicFragment.java | 24 +++ .../forum/post/ForumPostTopicViewModel.java | 7 + .../forum/{ => post}/ForumPostViewModel.java | 2 +- .../layout/forum/layout/forum_my_fragment.xml | 9 +- .../forum/layout/forum_new_fragment.xml | 8 +- .../layout/forum_post_active_fragment.xml | 77 +++++++++ .../layout/forum_post_complain_fragment.xml | 53 +++++++ .../forum/layout/forum_post_content.xml | 43 +++++ .../forum/layout/forum_post_fragment.xml | 46 +++++- .../layout/forum_post_topic_fragment.xml | 27 ++++ .../main/res/navigation/forum_navigation.xml | 2 +- .../res/navigation/nav_forum_post_type.xml | 23 +++ app/src/main/res/values-en-rUS/integers.xml | 5 + app/src/main/res/values-en-rUS/strings.xml | 14 ++ app/src/main/res/values-zh-rCN/integers.xml | 5 + app/src/main/res/values-zh-rCN/strings.xml | 14 ++ app/src/main/res/values/data.xml | 9 ++ app/src/main/res/values/integers.xml | 5 + app/src/main/res/values/strings.xml | 14 ++ 27 files changed, 673 insertions(+), 34 deletions(-) delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPostFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java rename app/src/main/java/com/community/pocket/ui/main/ui/forum/{ => post}/ForumPostViewModel.java (71%) create mode 100644 app/src/main/res/layout/main/layout/forum/layout/forum_post_active_fragment.xml create mode 100644 app/src/main/res/layout/main/layout/forum/layout/forum_post_complain_fragment.xml create mode 100644 app/src/main/res/layout/main/layout/forum/layout/forum_post_content.xml create mode 100644 app/src/main/res/layout/main/layout/forum/layout/forum_post_topic_fragment.xml create mode 100644 app/src/main/res/navigation/nav_forum_post_type.xml create mode 100644 app/src/main/res/values-en-rUS/integers.xml create mode 100644 app/src/main/res/values-zh-rCN/integers.xml create mode 100644 app/src/main/res/values/data.xml create mode 100644 app/src/main/res/values/integers.xml diff --git a/app/src/main/java/com/community/pocket/data/adapter/NoticeAdpter.java b/app/src/main/java/com/community/pocket/data/adapter/NoticeAdpter.java index 8c40896..ab92bb2 100644 --- a/app/src/main/java/com/community/pocket/data/adapter/NoticeAdpter.java +++ b/app/src/main/java/com/community/pocket/data/adapter/NoticeAdpter.java @@ -18,6 +18,7 @@ import java.util.List; /** * 公告内容 + * TODO 实现无限循环自动滚动 */ public class NoticeAdpter extends RecyclerView.Adapter { diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPostFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPostFragment.java deleted file mode 100644 index de138db..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPostFragment.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.community.pocket.ui.main.ui.forum; - -import com.community.pocket.R; -import com.community.pocket.ui.main.TestMainFragment; - -import org.xutils.view.annotation.ContentView; - -/** - * 发送帖子 - */ -@ContentView(R.layout.forum_post_fragment) -public class ForumPostFragment extends TestMainFragment { - - @Override - protected int viewId() { - return R.id.text_post; - } - -} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java new file mode 100644 index 0000000..0da4d83 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveFragment.java @@ -0,0 +1,35 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import com.community.pocket.R; + +import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.Event; +import org.xutils.view.annotation.ViewInject; + +/** + * 活动贴 + */ +@ContentView(R.layout.forum_post_active_fragment) +public class ForumPostActiveFragment extends ForumPostContent { + + @ViewInject(R.id.active_start_time) + private EditText activeStartTime; + + @ViewInject(R.id.active_end_time) + private EditText activeEndTime; + + @ViewInject(R.id.active_score) + private EditText activeScore; + + /** + * 发帖操作 + */ + @Event(value = R.id.post_button) + private void onButtonClick(View v) { + Toast.makeText(getContext(), R.string.post, Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java new file mode 100644 index 0000000..ac372e8 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostActiveViewModel.java @@ -0,0 +1,7 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import androidx.lifecycle.ViewModel; + +public class ForumPostActiveViewModel extends ViewModel { + // TODO: Implement the ViewModel +} 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 new file mode 100644 index 0000000..bec00fd --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainFragment.java @@ -0,0 +1,40 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import android.view.View; +import android.widget.AutoCompleteTextView; +import android.widget.TextView; +import android.widget.Toast; + +import com.community.pocket.R; + +import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.Event; +import org.xutils.view.annotation.ViewInject; + +/** + * 投诉贴 + */ +@ContentView(R.layout.forum_post_complain_fragment) +public class ForumPostComplainFragment extends ForumPostContent { + + /** + * 显示投诉人 + */ + @ViewInject(R.id.show_name) + private TextView showName; + + /** + * 检索投诉人 + */ + @ViewInject(R.id.search_name) + private AutoCompleteTextView searchName; + + + /** + * 发帖操作 + */ + @Event(value = R.id.post_button) + private void onButtonClick(View v) { + Toast.makeText(getContext(), R.string.post, Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java new file mode 100644 index 0000000..f3a78c5 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java @@ -0,0 +1,7 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import androidx.lifecycle.ViewModel; + +public class ForumPostComplainViewModel extends ViewModel { + // TODO: Implement the ViewModel +} 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 new file mode 100644 index 0000000..504b5f1 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java @@ -0,0 +1,147 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import android.annotation.SuppressLint; +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; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; + +import com.community.pocket.R; +import com.community.pocket.ui.BaseFragment; + +import org.xutils.view.annotation.ViewInject; + +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; + + + /** + * 导航 + */ + //TODO 临时方法,存在内存泄露 + @SuppressLint("StaticFieldLeak") + private static NavController nav; + + + /** + * 选择帖子类型触发事件 + */ + static Handler handler = new MyHandler(); + + + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + showCount(); + initPostCtrl(); + } + + + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + private static void nav(@IdRes int id) { + if (Objects.requireNonNull(nav.getCurrentDestination()).getId() != id) { + nav.navigate(id); + } + } + + + /** + * 初始化路由控制器 + */ + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + private void initPostCtrl() { + if (nav == null) { + nav = Navigation.findNavController(Objects.requireNonNull(getView())); + } + } + + /** + * 设置计数 + */ + 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) + @Override + public void handleMessage(@NonNull Message msg) { + switch (msg.what) { + case 0: + nav(R.id.forumPostActiveFragment); + break; + case 1: + nav(R.id.forumPostTopicFragment); + break; + case 2: + nav(R.id.forumPostComplainFragment); + break; + } + } + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java new file mode 100644 index 0000000..79dc03d --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java @@ -0,0 +1,64 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import android.os.Build; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.EditText; +import android.widget.Spinner; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; + +import com.community.pocket.R; +import com.community.pocket.ui.BaseFragment; + +import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.ViewInject; + +/** + * 发送帖子 + */ +@ContentView(R.layout.forum_post_fragment) +public class ForumPostFragment extends BaseFragment { + + /** + * 发送标题 + */ + @ViewInject(R.id.post_title) + private EditText postTitle; + + /** + * 帖子类型 + */ + @ViewInject(R.id.post_type) + private Spinner postType; + + + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + onPostTypeChange(); + } + + + /** + * 切换帖子类型 + */ + private void onPostTypeChange() { + postType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + ForumPostContent.handler.sendEmptyMessage(position); + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicFragment.java new file mode 100644 index 0000000..6872cb1 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicFragment.java @@ -0,0 +1,24 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import android.view.View; +import android.widget.Toast; + +import com.community.pocket.R; + +import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.Event; + +/** + * 动态贴 + */ +@ContentView(R.layout.forum_post_topic_fragment) +public class ForumPostTopicFragment extends ForumPostContent { + /** + * 发帖操作 + */ + @Event(value = R.id.post_button) + private void onButtonClick(View v) { + Toast.makeText(getContext(), R.string.post, Toast.LENGTH_SHORT).show(); + } + +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java new file mode 100644 index 0000000..b8c6430 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostTopicViewModel.java @@ -0,0 +1,7 @@ +package com.community.pocket.ui.main.ui.forum.post; + +import androidx.lifecycle.ViewModel; + +public class ForumPostTopicViewModel extends ViewModel { + // TODO: Implement the ViewModel +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPostViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostViewModel.java similarity index 71% rename from app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPostViewModel.java rename to app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostViewModel.java index f62bb59..fffa77e 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPostViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostViewModel.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.forum; +package com.community.pocket.ui.main.ui.forum.post; import androidx.lifecycle.ViewModel; diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml index d7bfa22..5a45b9f 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml @@ -3,11 +3,4 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ui.main.ui.forum.ForumMyFragment"> - - - - \ No newline at end of file + tools:context=".ui.main.ui.forum.ForumMyFragment" /> \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_new_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_new_fragment.xml index 4e1d577..3c84acf 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_new_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_new_fragment.xml @@ -14,6 +14,12 @@ android:id="@+id/post_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical" /> + android:orientation="vertical"> + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_post_active_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_post_active_fragment.xml new file mode 100644 index 0000000..974fe82 --- /dev/null +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_post_active_fragment.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + +