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 @@ + + + + + + + + + + + + + + + + +