From d12f84d4f51415be867ba51e116755f850b3e914 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Mon, 30 Mar 2020 22:29:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BF=E5=AE=A2=E7=AE=A1?= =?UTF-8?q?=E7=90=86-=E6=88=91=E7=9A=84=E9=A2=84=E7=BA=A6=E5=92=8C?= =?UTF-8?q?=E6=88=91=E7=9A=84=E8=AE=BF=E5=AE=A2=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + .../pocket/data/adapter/LocaleAdapter.java | 6 +- .../community/pocket/data/model/Visitor.java | 28 ++++ .../main/ui/forum/post/ForumPostContent.java | 19 +-- .../ui/main/ui/visitor/VisitorMyFragment.java | 25 +++- .../ui/main/ui/visitor/VisitorMyVisitor.java | 128 ++++++++++++++++++ .../visitor/VisitorReservationFragment.java | 28 +++- .../com/community/pocket/util/LocaleType.java | 4 +- .../forum/layout/forum_hot_fragment.xml | 4 +- .../layout/forum/layout/forum_my_fragment.xml | 4 +- .../forum/layout/forum_new_fragment.xml | 4 +- .../main/layout/forum/layout/forum_notice.xml | 4 +- .../forum/layout/forum_post_fragment.xml | 4 +- .../res/layout/main/layout/info_fragment.xml | 4 +- .../layout/visitor/layout/visitor_info.xml | 30 ++++ .../visitor/layout/visitor_my_fragment.xml | 101 +++++++++++++- .../layout/visitor_reservation_fragment.xml | 13 -- .../res/navigation/visitor_navigation.xml | 2 +- app/src/main/res/values-en-rUS/strings.xml | 12 ++ app/src/main/res/values-zh-rCN/strings.xml | 12 ++ app/src/main/res/values/strings.xml | 12 ++ 21 files changed, 389 insertions(+), 56 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/data/model/Visitor.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java create mode 100644 app/src/main/res/layout/main/layout/visitor/layout/visitor_info.xml delete mode 100644 app/src/main/res/layout/main/layout/visitor/layout/visitor_reservation_fragment.xml diff --git a/app/build.gradle b/app/build.gradle index d080ccc..909911f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,4 +52,5 @@ dependencies { implementation 'com.wuhenzhizao:titlebar:1.2.0' implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' + implementation 'androidx.gridlayout:gridlayout:1.0.0' } diff --git a/app/src/main/java/com/community/pocket/data/adapter/LocaleAdapter.java b/app/src/main/java/com/community/pocket/data/adapter/LocaleAdapter.java index e7fb2a0..e167188 100644 --- a/app/src/main/java/com/community/pocket/data/adapter/LocaleAdapter.java +++ b/app/src/main/java/com/community/pocket/data/adapter/LocaleAdapter.java @@ -49,13 +49,15 @@ public class LocaleAdapter extends BaseAdapter { } else { viewHolder = (ViewHolder) convertView.getTag(); } - String text = convertView.getResources().getString(LocaleType.getLocale(position).getResId()); + + String text = convertView.getContext().getString(LocaleType.getLocale(position).getResId()); viewHolder.childName.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); viewHolder.childName.setText(text); return convertView; } - private class ViewHolder { + + protected static class ViewHolder { @ViewInject(android.R.id.text1)//加载item的控件 TextView childName; } diff --git a/app/src/main/java/com/community/pocket/data/model/Visitor.java b/app/src/main/java/com/community/pocket/data/model/Visitor.java new file mode 100644 index 0000000..b44ddd1 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/Visitor.java @@ -0,0 +1,28 @@ +package com.community.pocket.data.model; + +/** + * 访客信息 + */ +public class Visitor { + private String name; + private long time; + private String notes; + + public Visitor(String name, long time, String notes) { + this.name = name; + this.time = time; + this.notes = notes; + } + + public String getName() { + return name; + } + + public long getTime() { + return time; + } + + public String getNotes() { + return notes; + } +} 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 25b7cf5..c0b16b0 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 @@ -7,7 +7,6 @@ import android.os.Handler; import android.os.Message; import android.view.View; -import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; @@ -50,22 +49,12 @@ abstract class ForumPostContent extends BaseFragment { } - @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())); - } + nav = Navigation.findNavController(Objects.requireNonNull(getView())); } @@ -79,13 +68,13 @@ abstract class ForumPostContent extends BaseFragment { public void handleMessage(@NonNull Message msg) { switch (msg.what) { case 0: - nav(R.id.forumPostActiveFragment); + nav.navigate(R.id.forumPostActiveFragment); break; case 1: - nav(R.id.forumPostTopicFragment); + nav.navigate(R.id.forumPostTopicFragment); break; case 2: - nav(R.id.forumPostComplainFragment); + nav.navigate(R.id.forumPostComplainFragment); break; } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java index abe7d83..5aa91fe 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java @@ -1,18 +1,35 @@ package com.community.pocket.ui.main.ui.visitor; +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.community.pocket.R; -import com.community.pocket.ui.main.TestMainFragment; import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.Event; /** * 我的访客界面 */ @ContentView(R.layout.visitor_my_fragment) -public class VisitorMyFragment extends TestMainFragment { +public class VisitorMyFragment extends VisitorMyVisitor { @Override - protected int viewId() { - return R.id.text_visitor; + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + name.setText(R.string.visitor_name); + time.setText(R.string.visitor_time); + } + + /** + * 查询访客数据 + */ + @Event(R.id.query) + private void query(View view) { + Toast.makeText(getContext(), "访客数据查询" + startTime.getText() + "|" + endTime.getText(), Toast.LENGTH_SHORT).show(); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java new file mode 100644 index 0000000..9967597 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java @@ -0,0 +1,128 @@ +package com.community.pocket.ui.main.ui.visitor; + +import android.os.Build; +import android.os.Bundle; +import android.text.format.DateFormat; +import android.view.Gravity; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AlertDialog; +import androidx.gridlayout.widget.GridLayout; + +import com.community.pocket.R; +import com.community.pocket.data.model.Visitor; +import com.community.pocket.ui.BaseFragment; + +import org.xutils.view.annotation.ViewInject; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public abstract class VisitorMyVisitor extends BaseFragment { + //表格布局 + @ViewInject(R.id.table) + private GridLayout gridLayout; + + //查询开始时间 + @ViewInject(R.id.start_time) + protected EditText startTime; + + //查询结束时间 + @ViewInject(R.id.end_time) + protected EditText endTime; + + //表格列 + @ViewInject(R.id.name) + protected TextView name; + + @ViewInject(R.id.time) + protected TextView time; + + /** + * 显示备注最大长度 + */ + private static final int maxLength = 5; + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + initDataList(); + } + + + /** + * 初始化数据 + * TODO 测试数据 + */ + private void initDataList() { + List visitors = new ArrayList<>(); + for (int i = 0; i < 30; i++) { + Visitor visitor = new Visitor("1231", System.currentTimeMillis(), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); + visitors.add(visitor); + } + + for (final Visitor visitor : visitors) { + createTextView(visitor.getName()); + createTextView(DateFormat.format(getString(R.string.dateformat), visitor.getTime())); + createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength)); + + Button button = new Button(getContext()); + button.setText(getString(R.string.show_notes)); + GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); + layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); + button.setLayoutParams(layoutParams); + button.setOnClickListener(new View.OnClickListener() { + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + @Override + public void onClick(View v) { + createAlertNotes(visitor.getNotes()); + } + }); + gridLayout.addView(button); + } + + } + + /** + * 创建单元格 + */ + private void createTextView(CharSequence text) { + TextView textView = new TextView(getContext()); + textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); + textView.setText(text); + textView.setBackground(getResources().getDrawable(R.drawable.border)); + GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); + layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); + textView.setLayoutParams(layoutParams); + gridLayout.addView(textView); + + } + + /** + * 创建显示备注信息弹窗 + */ + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + private void createAlertNotes(String text) { + View view = View.inflate(getContext(), R.layout.visitor_info, null); + EditText editText = view.findViewById(R.id.content); + editText.setText(text); + editText.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); + Button button = view.findViewById(R.id.close); + AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); + final AlertDialog alertDialog = alert.setTitle(R.string.notes).setView(view).create(); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + alertDialog.dismiss(); + } + }); + alertDialog.show(); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java index 87a6145..6761224 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java @@ -1,18 +1,36 @@ package com.community.pocket.ui.main.ui.visitor; +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.community.pocket.R; -import com.community.pocket.ui.main.TestMainFragment; import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.Event; /** * 我的预约界面 */ -@ContentView(R.layout.visitor_reservation_fragment) -public class VisitorReservationFragment extends TestMainFragment { +@ContentView(R.layout.visitor_my_fragment) +public class VisitorReservationFragment extends VisitorMyVisitor { @Override - protected int viewId() { - return R.id.text_reservation; + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + name.setText(R.string.appointment_name); + time.setText(R.string.appointment_time); + } + + + /** + * 查询预约数据 + */ + @Event(value = R.id.query) + private void query(View view) { + Toast.makeText(getContext(), "预约数据查询" + startTime.getText() + "|" + endTime.getText(), Toast.LENGTH_SHORT).show(); } } diff --git a/app/src/main/java/com/community/pocket/util/LocaleType.java b/app/src/main/java/com/community/pocket/util/LocaleType.java index a8ae033..aa5d5a3 100644 --- a/app/src/main/java/com/community/pocket/util/LocaleType.java +++ b/app/src/main/java/com/community/pocket/util/LocaleType.java @@ -1,5 +1,7 @@ package com.community.pocket.util; +import androidx.annotation.StringRes; + import com.community.pocket.R; import java.util.Locale; @@ -29,7 +31,7 @@ public enum LocaleType { return resId; } - LocaleType(Locale locale, int type, int resId) { + LocaleType(Locale locale, int type, @StringRes int resId) { this.locale = locale; this.type = type; this.resId = resId; 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 b8f361e..731c927 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 @@ -7,7 +7,7 @@ tools:context=".ui.main.ui.forum.ForumHotFragment"> - @@ -83,5 +83,5 @@ - + \ No newline at end of file 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 85e3a37..41931ca 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 @@ -5,7 +5,7 @@ android:layout_height="match_parent" tools:context=".ui.main.ui.forum.ForumMyFragment"> - @@ -21,5 +21,5 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - + \ 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 3c84acf..1bf0b25 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 @@ -5,7 +5,7 @@ android:layout_height="match_parent" tools:context=".ui.main.ui.forum.ForumNewFragment"> - @@ -21,5 +21,5 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml index 8e12c15..8358fa4 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_notice.xml @@ -16,7 +16,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - + - @@ -46,6 +46,6 @@ app:navGraph="@navigation/nav_forum_post_type" /> - + \ No newline at end of file diff --git a/app/src/main/res/layout/main/layout/info_fragment.xml b/app/src/main/res/layout/main/layout/info_fragment.xml index 9abbed0..7e721d1 100644 --- a/app/src/main/res/layout/main/layout/info_fragment.xml +++ b/app/src/main/res/layout/main/layout/info_fragment.xml @@ -7,7 +7,7 @@ android:layout_height="match_parent" tools:context=".ui.main.ui.info.InfoFragment"> - @@ -147,6 +147,6 @@ - + diff --git a/app/src/main/res/layout/main/layout/visitor/layout/visitor_info.xml b/app/src/main/res/layout/main/layout/visitor/layout/visitor_info.xml new file mode 100644 index 0000000..a5a3557 --- /dev/null +++ b/app/src/main/res/layout/main/layout/visitor/layout/visitor_info.xml @@ -0,0 +1,30 @@ + + + + + +