diff --git a/app/build.gradle b/app/build.gradle index af99f77..38abb9d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -90,8 +90,8 @@ dependencies { implementation 'androidx.annotation:annotation:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - implementation 'androidx.navigation:navigation-fragment:2.2.1' - implementation 'androidx.navigation:navigation-ui:2.2.1' + implementation 'androidx.navigation:navigation-fragment:2.2.2' + implementation 'androidx.navigation:navigation-ui:2.2.2' implementation 'androidx.vectordrawable:vectordrawable:1.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.13' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c5a1df7..5005786 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,8 @@ android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/Theme.AppCompat.Light.NoActionBar"> + android:theme="@style/Theme.AppCompat.Light.NoActionBar" + android:largeHeap="true"> @@ -35,6 +36,16 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/community/pocket/ui/BaseFragment.java b/app/src/main/java/com/community/pocket/ui/BaseFragment.java index 0cf79fa..5d64eba 100644 --- a/app/src/main/java/com/community/pocket/ui/BaseFragment.java +++ b/app/src/main/java/com/community/pocket/ui/BaseFragment.java @@ -23,7 +23,8 @@ public abstract class BaseFragment extends Fragment { @NonNull @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return x.view().inject(this, inflater, container);//fragment注解 + //fragment注解 + return x.view().inject(this, inflater, container); } //获取父级Fragment @@ -56,4 +57,5 @@ public abstract class BaseFragment extends Fragment { protected String formatUnix(Long time) { return DateFormat.format(getString(R.string.dateformat), time).toString(); } + } diff --git a/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java b/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java index a0318be..7af6e26 100644 --- a/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java +++ b/app/src/main/java/com/community/pocket/ui/login/LoginActivity.java @@ -43,6 +43,7 @@ import okhttp3.FormBody; /** * 登陆 + * @author panqihua */ @ContentView(R.layout.activity_login) @@ -76,7 +77,7 @@ public class LoginActivity extends BaseActivity { /** * 保存令牌到数据库并跳转到主界面 */ - private void saveTokenToDB(@NotNull final LoginResponse response) { + private void savetokentodb(@NotNull final LoginResponse response) { new Thread(() -> { Token token = response.getToken(); sInstance.tokenDao().save(token); @@ -153,7 +154,7 @@ public class LoginActivity extends BaseActivity { setResult(Activity.RESULT_OK); if (loginResponse.getResult() == Response.Result.OK) { - saveTokenToDB(loginResponse); + savetokentodb(loginResponse); } else { loginResponse.toast(getApplicationContext()); } diff --git a/app/src/main/java/com/community/pocket/ui/main/MainFragment.java b/app/src/main/java/com/community/pocket/ui/main/MainFragment.java index eacf1b3..3e78a2a 100644 --- a/app/src/main/java/com/community/pocket/ui/main/MainFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/MainFragment.java @@ -5,14 +5,13 @@ import android.view.View; import android.widget.Button; import androidx.annotation.RequiresApi; +import androidx.core.content.ContextCompat; import androidx.navigation.NavController; import androidx.navigation.Navigation; import com.community.pocket.R; import com.community.pocket.ui.BaseFragment; -import java.util.Objects; - /** * 二级菜单基础框架 */ @@ -41,20 +40,20 @@ public abstract class MainFragment extends BaseFragment { */ @RequiresApi(api = Build.VERSION_CODES.KITKAT) protected void changeColor(View view) { - int color = getResources().getColor(R.color.button_unchecked); - for (int id : button_ids()) { - View v = Objects.requireNonNull(getActivity()).findViewById(id); + int color = ContextCompat.getColor(requireContext(), R.color.button_unchecked); + for (int id : buttonIds()) { + View v = requireActivity().findViewById(id); v.setBackgroundColor(color); } if (view instanceof Button) { Button button = (Button) view; - button.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + button.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.colorAccent)); } } /** * 按钮组id */ - protected abstract int[] button_ids(); + protected abstract int[] buttonIds(); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java index 2b2a106..3dfd03b 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java @@ -64,6 +64,7 @@ public abstract class ForumPost extends BaseFragment { case uncheck: status.setText(R.string.forum_status_uncheck); break; + default: } TextView title = childView.findViewById(R.id.post_title); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java index 7dc5d51..9704fee 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/data/ForumDataActivity.java @@ -19,7 +19,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.widget.NestedScrollView; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; @@ -95,64 +94,50 @@ public class ForumDataActivity extends BaseActivity { viewModel.loadData(forumId); //监听回帖表单状态 - viewModel.getForumReplyState().observe(this, new Observer() { - @Override - public void onChanged(ForumReplyState forumReplyState) { - if (forumReplyState == null) { - return; - } - - if (forumReplyState.getContentError() != null) { - editText.setError(getString(forumReplyState.getContentError())); - } + viewModel.getForumReplyState().observe(this, forumReplyState -> { + if (forumReplyState == null) { + return; + } - reply.setEnabled(forumReplyState.isDataValid()); + if (forumReplyState.getContentError() != null) { + editText.setError(getString(forumReplyState.getContentError())); } + + reply.setEnabled(forumReplyState.isDataValid()); }); //监听回帖状态 - viewModel.getReplayResponse().observe(this, new Observer() { - @Override - public void onChanged(ForumDataResponse forumDataResponse) { - if (forumDataResponse == null) { - return; - } + viewModel.getReplayResponse().observe(this, forumDataResponse -> { + if (forumDataResponse == null) { + return; + } - forumDataResponse.toast(getBaseContext()); + forumDataResponse.toast(getBaseContext()); - if (forumDataResponse.getResult() == Response.Result.OK) { - handler.sendEmptyMessage(0); - viewModel.loadData(forumId); - } + if (forumDataResponse.getResult() == Response.Result.OK) { + handler.sendEmptyMessage(0); + viewModel.loadData(forumId); } }); //监听帖子详情数据 - viewModel.getForumContentResponse().observe(this, new Observer() { - @Override - public void onChanged(ForumDataResponse listForumDataResponse) { - if (listForumDataResponse == null) { - return; - } + viewModel.getForumContentResponse().observe(this, listForumDataResponse -> { + if (listForumDataResponse == null) { + return; + } - listForumDataResponse.toast(getBaseContext()); + listForumDataResponse.toast(getBaseContext()); - if (listForumDataResponse.getResult() == Response.Result.OK) { - List forumContents = listForumDataResponse.getForumContentList(); - initFirst(forumContents.get(0), listForumDataResponse.getForum()); - if (forumContents.size() > 1) { - createReply(forumContents.subList(1, forumContents.size())); - } + if (listForumDataResponse.getResult() == Response.Result.OK) { + List forumContents = listForumDataResponse.getForumContentList(); + initFirst(forumContents.get(0), listForumDataResponse.getForum()); + if (forumContents.size() > 1) { + createReply(forumContents.subList(1, forumContents.size())); } } }); - openReply.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - showContent(); - } - }); + openReply.setOnClickListener(v -> showContent()); } } @@ -166,12 +151,7 @@ public class ForumDataActivity extends BaseActivity { //关闭回帖窗口按钮 Button close = alertView.findViewById(R.id.close); reply = alertView.findViewById(R.id.reply); - reply.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - viewModel.sendReply(forumId, editText.getText().toString()); - } - }); + reply.setOnClickListener(v -> viewModel.sendReply(forumId, editText.getText().toString())); editText.addTextChangedListener(new MyTextChange() { @Override @@ -193,12 +173,7 @@ public class ForumDataActivity extends BaseActivity { } }; - close.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - handler.sendEmptyMessage(0); - } - }); + close.setOnClickListener(v -> handler.sendEmptyMessage(0)); alertDialog.show(); } @@ -239,6 +214,7 @@ public class ForumDataActivity extends BaseActivity { $complain.setText(getString(R.string.forum_show_complain, complain.getComplain())); } break; + default: } if (childView != null) { otherContent.removeAllViews(); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java index 600e1df..8675175 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/hot/ForumHotFragment.java @@ -11,7 +11,6 @@ import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; @@ -40,18 +39,15 @@ public class ForumHotFragment extends BaseFragment { viewModel.loadHot(); //加载热门信息 - viewModel.getForumHotResponse().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(ForumHotResponse forumHotResponse) { - if (forumHotResponse == null) { - return; - } - - forumHotResponse.toast(getContext()); - - if (forumHotResponse.getResult() == Response.Result.OK) { - loadRank(forumHotResponse.getHot()); - } + viewModel.getForumHotResponse().observe(getViewLifecycleOwner(), forumHotResponse -> { + if (forumHotResponse == null) { + return; + } + + forumHotResponse.toast(getContext()); + + if (forumHotResponse.getResult() == Response.Result.OK) { + loadRank(forumHotResponse.getHot()); } }); } @@ -85,7 +81,7 @@ public class ForumHotFragment extends BaseFragment { //文本居中 textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); //字体大小 - textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); textView.setId(View.generateViewId()); //设置约束 ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java index 50925c8..90e786b 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/main/ForumFragment.java @@ -12,6 +12,7 @@ import android.widget.ImageView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; +import androidx.core.content.ContextCompat; import androidx.core.widget.NestedScrollView; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModelProvider; @@ -102,6 +103,7 @@ public class ForumFragment extends MainFragment { case MotionEvent.ACTION_UP: v.setAlpha(0.1f); break; + default: } return false; }); @@ -142,8 +144,9 @@ public class ForumFragment extends MainFragment { banner.setAdapter(new NoticeAdpter(notices)); banner.setIndicator(new RectangleIndicator(getContext())); banner.setIndicatorWidth(100, 200); - banner.setIndicatorNormalColor(getResources().getColor(R.color.colorAccent)); - banner.setIndicatorSelectedColor(getResources().getColor(R.color.colorBlack)); + + banner.setIndicatorNormalColor(ContextCompat.getColor(requireContext(), R.color.colorAccent)); + banner.setIndicatorSelectedColor(ContextCompat.getColor(requireContext(), R.color.colorBlack)); if (notices.size() >= 2) { noticePrev.setVisibility(View.VISIBLE); @@ -204,7 +207,7 @@ public class ForumFragment extends MainFragment { } @Override - protected int[] button_ids() { + protected int[] buttonIds() { return new int[]{R.id.forum_hot, R.id.forum_new, R.id.forum_post, R.id.forum_my}; } } 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 index 483ee6d..c7ff446 100644 --- 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 @@ -18,8 +18,6 @@ import com.community.pocket.ui.BaseFragment; import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ViewInject; -import java.util.Objects; - /** * 发送帖子 */ @@ -54,7 +52,7 @@ public class ForumPostFragment extends BaseFragment { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { if (nav == null) { - nav = Navigation.findNavController(Objects.requireNonNull(getView()).findViewById(R.id.post_type_fragment)); + nav = Navigation.findNavController(requireView().findViewById(R.id.post_type_fragment)); } else { switch (position) { case 0: @@ -68,7 +66,8 @@ public class ForumPostFragment extends BaseFragment { break; case 3: nav.navigate(R.id.forumPostComplainFragment); - + break; + default: } } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageFragment.java index 68c77e4..da78a02 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/GarbageFragment.java @@ -36,7 +36,7 @@ public class GarbageFragment extends MainFragment { } @Override - protected int[] button_ids() { + protected int[] buttonIds() { return new int[]{R.id.garbage_sorting, R.id.garbage_waste}; } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java index 7b8996e..ea08c87 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java @@ -9,7 +9,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; @@ -58,18 +57,15 @@ public class GarbageSortingFragment extends BaseFragment { myAutoCompleteTextView = new MyAutoCompleteTextView(searchSorting, viewModel); //监听垃圾分类检索状态 - viewModel.getGarbageSortingResponse().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(GarbageSortingResponse garbageSortingResponse) { - if (garbageSortingResponse == null) { - return; - } + viewModel.getGarbageSortingResponse().observe(getViewLifecycleOwner(), garbageSortingResponse -> { + if (garbageSortingResponse == null) { + return; + } - garbageSortingResponse.toast(getContext()); + garbageSortingResponse.toast(getContext()); - if (garbageSortingResponse.getResult() == Response.Result.OK) { - initSearch(garbageSortingResponse.getGarbageSortings()); - } + if (garbageSortingResponse.getResult() == Response.Result.OK) { + initSearch(garbageSortingResponse.getGarbageSortings()); } }); @@ -111,6 +107,7 @@ public class GarbageSortingFragment extends BaseFragment { case 4:resId=R.string.garbage_category_4;break; case 8:resId=R.string.garbage_category_8;break; case 16:resId=R.string.garbage_category_16;break; + default: } sorting.setText(resId); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java index 58e64b9..aca0c95 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java @@ -10,8 +10,8 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import androidx.gridlayout.widget.GridLayout; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; @@ -60,34 +60,28 @@ public class GarbageWasteFragment extends BaseFragment { viewModel.searchDefault(); //监听默认废品信息请求状态 - viewModel.getDefaultList().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(GarbageWasteResponse garbageWasteResponse) { - if (garbageWasteResponse == null) { - return; - } + viewModel.getDefaultList().observe(getViewLifecycleOwner(), garbageWasteResponse -> { + if (garbageWasteResponse == null) { + return; + } - garbageWasteResponse.toast(getContext()); + garbageWasteResponse.toast(getContext()); - if (garbageWasteResponse.getResult() == Response.Result.OK) { - initDefault(garbageWasteResponse.getDefaultList(), garbageWasteResponse.getGarbageWasteManage()); - } + if (garbageWasteResponse.getResult() == Response.Result.OK) { + initDefault(garbageWasteResponse.getDefaultList(), garbageWasteResponse.getGarbageWasteManage()); } }); //监听废品信息请求状态 - viewModel.getSearchList().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(GarbageWasteResponse garbageWasteResponse) { - if (garbageWasteResponse == null) { - return; - } + viewModel.getSearchList().observe(getViewLifecycleOwner(), garbageWasteResponse -> { + if (garbageWasteResponse == null) { + return; + } - garbageWasteResponse.toast(getContext()); + garbageWasteResponse.toast(getContext()); - if (garbageWasteResponse.getResult() == Response.Result.OK) { - initSearch(garbageWasteResponse.getSearchList()); - } + if (garbageWasteResponse.getResult() == Response.Result.OK) { + initSearch(garbageWasteResponse.getSearchList()); } }); //检索内容改变触发监听器 @@ -150,8 +144,8 @@ public class GarbageWasteFragment extends BaseFragment { 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)); - textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24); + textView.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.border)); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); textView.setLayoutParams(layoutParams); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java index d334a6e..427a7a8 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java @@ -5,12 +5,12 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; +import android.graphics.ImageDecoder; import android.graphics.Paint; import android.graphics.Rect; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -30,9 +30,11 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AlertDialog; +import androidx.core.content.FileProvider; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModelProvider; +import com.community.pocket.BuildConfig; import com.community.pocket.R; import com.community.pocket.data.model.CreditScore; import com.community.pocket.data.model.LocalToken; @@ -60,11 +62,11 @@ import org.xutils.view.annotation.Event; import org.xutils.view.annotation.ViewInject; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Objects; /** * 我的信息框架 @@ -130,11 +132,18 @@ public class InfoFragment extends BaseFragment { //上传头像 private Handler uploadImgHandler; + //压缩头像 + private Handler compressHandler; + //检测是否有读写文件权限 private MutableLiveData bool = new MutableLiveData<>(); + //拍照uri + private Uri photoUri; + + //显示信用分图表要求的最小记录数 + private static final int MIN_HISTORY = 2; - @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -217,16 +226,18 @@ public class InfoFragment extends BaseFragment { if (infoResponse == null) { return; } - - uploadImgHandler.sendEmptyMessage(infoResponse.getResult().ordinal()); - + if (uploadImgHandler != null) { + uploadImgHandler.sendEmptyMessage(infoResponse.getResult().ordinal()); + } infoResponse.toast(getContext()); }); //监听获取头像状态 viewModel.getGetImg().observe(getViewLifecycleOwner(), bitmap -> headimg.setImageBitmap(bitmap)); + } + /** * 加载个人信息 * @@ -243,7 +254,7 @@ public class InfoFragment extends BaseFragment { viewModel.getImg(myInfo.getHeadImg()); } - if (myInfo.getScoreHistory() != null && myInfo.getScoreHistory().size() >= 2) { + if (myInfo.getScoreHistory() != null && myInfo.getScoreHistory().size() >= MIN_HISTORY) { loadChart(myInfo.getScoreHistory()); } } @@ -269,10 +280,13 @@ public class InfoFragment extends BaseFragment { if (file.exists()) { bool.postValue(true); } else { - bool.postValue(false); - String msg = "无法创建照片目录"; - Log.e(InfoFragment.class.getName(), msg); - throw new RuntimeException(msg); + boolean mkdirs = file.mkdirs(); + bool.postValue(mkdirs); + if (!mkdirs) { + String msg = "无法创建照片目录"; + Log.e(InfoFragment.class.getName(), msg); + throw new RuntimeException(msg); + } } } @@ -284,14 +298,13 @@ public class InfoFragment extends BaseFragment { } - /** * 点击头像操作 */ private void clickHeadImg() { bool.observe(getViewLifecycleOwner(), aBoolean -> { if (aBoolean) { - headimg.setOnClickListener(v -> new AlertDialog.Builder(Objects.requireNonNull(getContext())) + headimg.setOnClickListener(v -> new AlertDialog.Builder(requireContext()) .setNegativeButton(R.string.open_photo_album, (dialog, which) -> { // 打开相册 Intent intent = new Intent(Intent.ACTION_PICK); @@ -303,12 +316,20 @@ public class InfoFragment extends BaseFragment { File file = getPhotoDir(); File photoFile = new File(file, System.currentTimeMillis() + "origin.png"); - Log.i(InfoFragment.class.getName(), "图片存储到" + photoFile.getAbsolutePath()); + Log.i(InfoFragment.class.getName(), "图片存储到:" + photoFile.getAbsolutePath()); + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + photoUri = Uri.fromFile(photoFile); + } else { + photoUri = FileProvider.getUriForFile( + requireContext(), + BuildConfig.APPLICATION_ID + ".fileprovider", + photoFile); + } // 隐式意图打开系统界面 --要求回传 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // 存到什么位置 - intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); - intent.putExtra(Action.OPEN_CAMERA.name(), photoFile); + intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); startActivityForResult(intent, Action.OPEN_CAMERA.ordinal()); }) .setPositiveButton(R.string.action_close, (dialog, which) -> dialog.dismiss()).show()); @@ -320,7 +341,7 @@ public class InfoFragment extends BaseFragment { } private File getPhotoDir() { - return new File(Environment.getExternalStorageDirectory(), + return new File(requireContext().getExternalCacheDir(), getString(R.string.app_name)); } @@ -331,38 +352,72 @@ public class InfoFragment extends BaseFragment { //判断是否有裁剪应用 private boolean hasCrop() { - Context context = getContext(); - return context != null && getCropIntent().resolveActivity(getContext().getPackageManager()) != null; + return getCropIntent().resolveActivity(requireContext().getPackageManager()) != null; } //设置头像 - private void setHeadImg(Bitmap bitmap) { + private void setHeadImg(Uri uri) { File picFile = new File(getPhotoDir(), System.currentTimeMillis() + ".png"); try { if (picFile.createNewFile()) { - bitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream( - picFile)); - Context context = Objects.requireNonNull(getContext()); - TextView textView = new TextView(context); + + + Bitmap bitmap; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + bitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(requireContext().getContentResolver(), uri)); + + } else { + bitmap = MediaStore.Images.Media.getBitmap(requireContext().getContentResolver(), uri); + } + Context context = requireContext(); + TextView textView = new TextView(getContext()); textView.setTextSize(18); textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); - textView.setText(R.string.upload_img); - AlertDialog alertDialog = new AlertDialog.Builder(context) - .setView(textView).show(); - uploadImgHandler = new Handler(Looper.getMainLooper()) { + textView.setText(R.string.compress_img); + + AlertDialog uploadDialog = new AlertDialog.Builder(context) + .setView(textView).setCancelable(false).show(); + compressHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(@NonNull Message msg) { - alertDialog.dismiss(); if (msg.what == Response.Result.OK.ordinal()) { - headimg.setImageBitmap(bitmap); + Log.i(InfoFragment.class.getName(), "位图大小:" + bitmap.getByteCount() / 1024 + "KB" + ",压缩大小" + picFile.length() / 1024 + "KB"); + uploadImgHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(@NonNull Message msg) { + uploadDialog.dismiss(); + if (msg.what == Response.Result.OK.ordinal()) { + headimg.setImageBitmap(bitmap); + } + } + }; + textView.setText(R.string.upload_img); + viewModel.uploadImg(picFile); + } else { + uploadDialog.dismiss(); + Toast.makeText(context, R.string.unknow_error, Toast.LENGTH_LONG).show(); } } }; - viewModel.uploadImg(picFile); + + new Thread(() -> { + try { + bitmap.compress(Bitmap.CompressFormat.PNG, getResources().getInteger(R.integer.photo_quality), new FileOutputStream( + picFile)); + compressHandler.sendEmptyMessage(Response.Result.OK.ordinal()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + Log.e(InfoFragment.class.getName(), e.toString()); + compressHandler.sendEmptyMessage(Response.Result.FAIL.ordinal()); + } + }).start(); + + } } catch (IOException e) { e.printStackTrace(); Log.e(InfoFragment.class.getName(), e.toString()); + Toast.makeText(getContext(), R.string.unknow_error, Toast.LENGTH_LONG).show(); } } @@ -394,35 +449,12 @@ public class InfoFragment extends BaseFragment { @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { Log.i(InfoFragment.class.getName(), "requestCode:" + requestCode + ",resultCode:" + resultCode); - - if (data != null) { - //获取路径 - if (requestCode == Action.OPEN_GALLERY.ordinal() || requestCode == Action.OPEN_CAMERA.ordinal()) { - if (hasCrop()) { - crop(data.getData()); - } else { - Context context = getContext(); - if (context != null) { - try { - Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContext().getContentResolver(), data.getData()); - setHeadImg(bitmap); - } catch (IOException e) { - e.printStackTrace(); - Log.e(InfoFragment.class.getName(), e.toString()); - } - } else { - Log.e(InfoFragment.class.getName(), "无法获取Context"); - } - } - } else if (requestCode == Action.CROP.ordinal()) { - //直接拿到一张图片 - Bitmap bitmap = data.getParcelableExtra("data"); - if (bitmap != null) { - setHeadImg(bitmap); - } else { - Log.e(InfoFragment.class.getName(), "无法获取裁剪图片"); - } - } + //获取图片路径 + if (requestCode == Action.OPEN_GALLERY.ordinal() && data != null && data.getData() != null) { + setHeadImg(data.getData()); + } else if (requestCode == Action.OPEN_CAMERA.ordinal() && photoUri != null) { + setHeadImg(photoUri); + photoUri = null; } } @@ -450,7 +482,7 @@ public class InfoFragment extends BaseFragment { newPwd.addTextChangedListener(textWatcher); confirmNewPwd.addTextChangedListener(textWatcher); - AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); + AlertDialog.Builder alert = new AlertDialog.Builder(requireContext()); final AlertDialog alertDialog = alert.setTitle(R.string.modify_password).setView(view) .setNegativeButton(R.string.modify_password, (dialog, which) -> { viewModel.modifyPwd(oldPwd.getText().toString(), newPwd.getText().toString()); @@ -494,7 +526,7 @@ public class InfoFragment extends BaseFragment { return Utils.convertPixelsToDp(rect.left + rect.right); } - // + //折线图添加数据源 private LineDataSet addChart(List values) { List entryList = new ArrayList<>(); @@ -537,8 +569,8 @@ public class InfoFragment extends BaseFragment { xAxis.setDrawGridLines(false); //设置Y轴数据格式 - initYAxis(lineChart.getAxisLeft(), textSize); - initYAxis(lineChart.getAxisRight(), textSize); + inityaxis(lineChart.getAxisLeft(), textSize); + inityaxis(lineChart.getAxisRight(), textSize); //设置x轴0刻度和最后刻度的左右偏移,保证日期显示完整 float offset = computeTextWidth(getString(R.string.dateformat), textSize) + 3; @@ -558,7 +590,7 @@ public class InfoFragment extends BaseFragment { legend.setEnabled(false); } - private void initYAxis(YAxis yAxis, int textSize) { + private void inityaxis(YAxis yAxis, int textSize) { //轴细分粒度最小单位长度 yAxis.setAxisMinimum(1); //轴间隔最小单位长度 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/share/MyAutoCompleteTextView.java b/app/src/main/java/com/community/pocket/ui/main/ui/share/MyAutoCompleteTextView.java index 018174a..a6433c2 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/share/MyAutoCompleteTextView.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/share/MyAutoCompleteTextView.java @@ -32,6 +32,7 @@ public class MyAutoCompleteTextView { //延时搜索的handler private Handler searchHandler = new Handler(Looper.getMainLooper()) { + @Override public void handleMessage(@NotNull Message msg) { dealSearchHint(msg.getData()); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java b/app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java index c92da13..6f6616d 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java @@ -1,9 +1,13 @@ package com.community.pocket.ui.main.ui.share; import android.content.Context; +import android.content.Intent; import android.widget.Toast; import com.community.pocket.R; +import com.community.pocket.data.model.LocalToken; +import com.community.pocket.ui.login.LoginActivity; +import com.community.pocket.util.AppDatabase; import com.community.pocket.util.CustomMessage; /** @@ -48,6 +52,13 @@ public abstract class Response { public void toast(Context context) { if (getMessage() != null) { Toast.makeText(context, context.getString(getMessage().getMsg(), getArgs()), getResult() == Result.OK ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG).show(); + if (getMessage().getMsg() == R.string.invalid_token) { + new Thread(() -> { + AppDatabase.getInstance(context).tokenDao().delete(LocalToken.getTokenInstance()); + LocalToken.logout(); + context.startActivity(new Intent(context, LoginActivity.class)); + }).start(); + } } else { Toast.makeText(context, R.string.unknow_error, Toast.LENGTH_LONG).show(); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/share/ShowWordCount.java b/app/src/main/java/com/community/pocket/ui/main/ui/share/ShowWordCount.java index 7318562..98320ba 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/share/ShowWordCount.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/share/ShowWordCount.java @@ -1,5 +1,6 @@ package com.community.pocket.ui.main.ui.share; +import android.os.Build; import android.text.Html; import android.view.View; import android.widget.EditText; @@ -23,7 +24,7 @@ public class ShowWordCount { private EditText postContent; - private static final int length = PropertiesUtil.getIntValue("textMultiLine.length"); + private static final int LENGTH = PropertiesUtil.getIntValue("textMultiLine.length"); public ShowWordCount(int[] ids, int contentId, View view) { this.ids = ids; @@ -35,11 +36,15 @@ public class ShowWordCount { * 设置计数 */ private void setCount() { - String text = view.getContext().getString(R.string.post_content_count, postContent.length(), length); + String text = view.getContext().getString(R.string.post_content_count, postContent.length(), LENGTH); for (int id : ids) { TextView textView = view.findViewById(id); - textView.setText(Html.fromHtml(text)); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) { + textView.setText(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)); + } else { + textView.setText(Html.fromHtml(text)); + } } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java index 01772d2..2dc3f0e 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java @@ -70,7 +70,7 @@ public class VisitorFragment extends MainFragment { } @Override - protected int[] button_ids() { + protected int[] buttonIds() { return new int[]{R.id.visitor_appointment, R.id.visitor_reservation, R.id.visitor_visitor}; } } 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 index 5e65266..38513ee 100644 --- 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 @@ -15,6 +15,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; +import androidx.core.content.ContextCompat; import androidx.core.widget.NestedScrollView; import androidx.gridlayout.widget.GridLayout; @@ -27,8 +28,6 @@ import com.community.pocket.util.PropertiesUtil; import org.xutils.view.annotation.Event; import org.xutils.view.annotation.ViewInject; -import java.util.Objects; - /** * 访客列表通用布局 */ @@ -58,7 +57,7 @@ public abstract class VisitorMyVisitor extends BaseFragment { /** * 显示备注最大长度 */ - private static final int maxLength = 5; + private static final int MAX_LENGTH = 5; @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { @@ -74,10 +73,10 @@ public abstract class VisitorMyVisitor extends BaseFragment { if (visitors.getCurrentPage() == 1 && !visitors.isEmpty()) { gridLayout.removeViews(4, gridLayout.getChildCount() - 4); } - for (final Visitor visitor : visitors.getList()) { + for (Visitor visitor : visitors.getList()) { createTextView(visitor.getName()); createTextView(DateFormat.format(getString(R.string.dateformat_visitor), visitor.getTime())); - createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength)); + createTextView(visitor.getNotes().length() <= MAX_LENGTH ? visitor.getNotes() : visitor.getNotes().substring(0, MAX_LENGTH)); switch (visitor.getStatus()) { case ok: @@ -95,7 +94,7 @@ public abstract class VisitorMyVisitor extends BaseFragment { case fail: createTextView(R.string.visitor_check_fail); break; - + default: } } @@ -139,11 +138,12 @@ public abstract class VisitorMyVisitor extends BaseFragment { private void createTextView(TextView textView) { textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); - textView.setBackground(getResources().getDrawable(R.drawable.border)); + + textView.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.border)); GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); textView.setLayoutParams(layoutParams); - textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); gridLayout.addView(textView); } @@ -162,7 +162,7 @@ public abstract class VisitorMyVisitor extends BaseFragment { TextView admin = view.findViewById(R.id.admin); admin.setText(getString(R.string.visitor_show_admin, visitor.getManagerName())); Button button = view.findViewById(R.id.close); - AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); + AlertDialog.Builder alert = new AlertDialog.Builder(requireContext()); final AlertDialog alertDialog = alert.setTitle(R.string.visitor_traffic_permit).setView(view).create(); button.setOnClickListener(v -> alertDialog.dismiss()); alertDialog.show(); diff --git a/app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java b/app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java index ac3b731..ed34062 100644 --- a/app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java +++ b/app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java @@ -28,6 +28,7 @@ public class RegisterResponse extends Response { this.msg = msg; } + @Override @NotNull public @StringRes Integer getMsg() { diff --git a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java index 60ced31..fa697ed 100644 --- a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java @@ -102,7 +102,7 @@ public class ResetPwdViewModel extends BaseViewModel { //监听重置密码第二步表单触发校验 void resetpwdStep2Changed(String code) { - if (!ValidUtil.CAPTCHAValid(code)) { + if (!ValidUtil.captchavalid(code)) { resetPwdFormStep2.setValue(new ResetPwdFormState.Step2(R.string.invalid_CAPTCHA)); } else { resetPwdFormStep2.setValue(new ResetPwdFormState.Step2(true)); diff --git a/app/src/main/java/com/community/pocket/util/HttpFileResponse.java b/app/src/main/java/com/community/pocket/util/HttpFileResponse.java index ebf9bc6..a469866 100644 --- a/app/src/main/java/com/community/pocket/util/HttpFileResponse.java +++ b/app/src/main/java/com/community/pocket/util/HttpFileResponse.java @@ -17,7 +17,7 @@ import okhttp3.ResponseBody; public class HttpFileResponse implements Callback { - private static final String header = "Content-Type"; + private static final String HEADER = "Content-Type"; private final MutableLiveData image; @@ -33,7 +33,7 @@ public class HttpFileResponse implements Callback { @Override public void onResponse(@NotNull Call call, @NotNull Response response) { - String contentType = response.header(header); + String contentType = response.header(HEADER); if ("image/png".equals(contentType)) { ResponseBody responseBody = response.body(); if (responseBody != null) { @@ -41,7 +41,7 @@ public class HttpFileResponse implements Callback { image.postValue(bitmap); } } else { - onParseError(call, response, "接口不是响应图片数据,非法响应头" + header + "=" + contentType); + onParseError(call, response, "接口不是响应图片数据,非法响应头" + HEADER + "=" + contentType); } } diff --git a/app/src/main/java/com/community/pocket/util/HttpJSONResponse.java b/app/src/main/java/com/community/pocket/util/HttpJSONResponse.java index 4a62430..29addda 100644 --- a/app/src/main/java/com/community/pocket/util/HttpJSONResponse.java +++ b/app/src/main/java/com/community/pocket/util/HttpJSONResponse.java @@ -25,7 +25,9 @@ public class HttpJSONResponse httpParse; - private static final String header = "Content-Type"; + private static final String HEADER = "Content-Type"; + + private static final String JSON = "json"; public HttpJSONResponse(Class tClass, HttpParse httpParse) { this.tClass = tClass; @@ -40,8 +42,8 @@ public class HttpJSONResponse 1) { runtimeException = new RuntimeException(c.getName() + "包含多个方法名为:" + methodName + "的方法!!!"); } else { runtimeException = new RuntimeException("类:" + c.getName() + "方法:" + methodName + "缺少注解" + HttpRequest.class + ",无法调用" + HttpUtil.class); } } else { - httpRequest = map.get(className + methodName); + httpRequest = MAP.get(className + methodName); } if (httpRequest != null) { return httpRequest.value(); diff --git a/app/src/main/java/com/community/pocket/util/PermissionsUtils.java b/app/src/main/java/com/community/pocket/util/PermissionsUtils.java index 722287c..82c28b9 100644 --- a/app/src/main/java/com/community/pocket/util/PermissionsUtils.java +++ b/app/src/main/java/com/community/pocket/util/PermissionsUtils.java @@ -18,8 +18,8 @@ import java.util.ArrayList; import java.util.List; public class PermissionsUtils { - - private final int mRequestCode = 100;//权限请求码 + //权限请求码 + private final int mRequestCode = 100; private PermissionsUtils() { } @@ -36,8 +36,8 @@ public class PermissionsUtils { public void checkPermissions(Activity context, String[] permissions, @NonNull IPermissionsResult permissionsResult) { mPermissionsResult = permissionsResult; - - if (Build.VERSION.SDK_INT < 23) {//6.0才用动态权限 +//6.0才用动态权限 + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { permissionsResult.passPermissons(); return; } @@ -47,7 +47,8 @@ public class PermissionsUtils { //逐个判断你要的权限是否已经通过 for (String permission : permissions) { if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { - mPermissionList.add(permission);//添加还未授予的权限 + //添加还未授予的权限 + mPermissionList.add(permission); } } @@ -67,7 +68,8 @@ public class PermissionsUtils { public void onRequestPermissionsResult(Activity context, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - boolean hasPermissionDismiss = false;//有权限没有通过 + //有权限没有通过 + boolean hasPermissionDismiss = false; if (mRequestCode == requestCode) { for (int grantResult : grantResults) { if (grantResult == -1) { @@ -78,7 +80,8 @@ public class PermissionsUtils { //如果有权限没有被允许 if (hasPermissionDismiss) { if (context.getResources().getBoolean(R.bool.showSystemSetting)) { - showSystemPermissionsSettingDialog(context);//跳转到系统设置权限页面,或者直接关闭页面,不让他继续访问 + //跳转到系统设置权限页面,或者直接关闭页面,不让他继续访问 + showSystemPermissionsSettingDialog(context); } else { mPermissionsResult.forbitPermissons(); } @@ -103,8 +106,8 @@ public class PermissionsUtils { .setPositiveButton("设置", (dialog, which) -> { cancelPermissionDialog(); - Uri packageURI = Uri.parse("package:" + mPackName); - Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI); + Uri packageuri = Uri.parse("package:" + mPackName); + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageuri); context.startActivity(intent); context.finish(); }) diff --git a/app/src/main/java/com/community/pocket/util/PropertiesUtil.java b/app/src/main/java/com/community/pocket/util/PropertiesUtil.java index a6e1d70..84668c1 100644 --- a/app/src/main/java/com/community/pocket/util/PropertiesUtil.java +++ b/app/src/main/java/com/community/pocket/util/PropertiesUtil.java @@ -10,15 +10,15 @@ public class PropertiesUtil { private static Properties properties; - private final static Map values = new HashMap<>(); + private final static Map VALUES = new HashMap<>(); // 文件路径 - private static final String filePath = "/assets/config.properties"; + private static final String FILE_PATH = "/assets/config.properties"; static { properties = new Properties(); try { - InputStream is = PropertiesUtil.class.getResourceAsStream(filePath); + InputStream is = PropertiesUtil.class.getResourceAsStream(FILE_PATH); properties.load(is); } catch (Exception e) { e.printStackTrace(); @@ -27,11 +27,11 @@ public class PropertiesUtil { //获取字符串配置 public static String getValue(String key) { - if (values.containsKey(key)) { - return values.get(key); + if (VALUES.containsKey(key)) { + return VALUES.get(key); } else { String value = properties.getProperty(key); - values.put(key, value); + VALUES.put(key, value); return value; } } diff --git a/app/src/main/java/com/community/pocket/util/ValidUtil.java b/app/src/main/java/com/community/pocket/util/ValidUtil.java index 9db539e..d1ee8e5 100644 --- a/app/src/main/java/com/community/pocket/util/ValidUtil.java +++ b/app/src/main/java/com/community/pocket/util/ValidUtil.java @@ -12,8 +12,16 @@ import java.util.regex.Pattern; /** * 表单校验工具类 */ +@SuppressWarnings("AlibabaAvoidPatternCompileInMethod") public class ValidUtil { + private static final Pattern PHONE = Pattern.compile("^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$"); + + private static final Pattern CAPTCHA = Pattern.compile("^\\d{6}$"); + + private static final Pattern DATE = Pattern.compile("^\\d{2}:\\d{2}$"); + + private static final Pattern NUM = Pattern.compile("^\\d+$"); /** * 校验邮箱 */ @@ -25,7 +33,7 @@ public class ValidUtil { * 校验手机号 */ public static boolean mobilePhoneValid(String mobilePhone) { - return Pattern.compile("^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$").matcher(mobilePhone).matches(); + return PHONE.matcher(mobilePhone).matches(); } /** @@ -45,15 +53,15 @@ public class ValidUtil { /** * 校验验证码 */ - public static boolean CAPTCHAValid(String code) { - return Pattern.compile("^\\d{6}$").matcher(code).matches(); + public static boolean captchavalid(String code) { + return CAPTCHA.matcher(code).matches(); } /** * 校验预约时间 */ public static boolean timeValid(Object time) { - return time != null && Pattern.compile("^\\d{2}:\\d{2}$").matcher(time.toString()).matches(); + return time != null && DATE.matcher(time.toString()).matches(); } /** @@ -90,11 +98,6 @@ public class ValidUtil { format.parse(str); } catch (ParseException e) { - -// e.printStackTrace(); - -// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对 - convertSuccess = false; } @@ -128,7 +131,7 @@ public class ValidUtil { * 校验信用分 */ public static boolean scoreValid(String score) { - if (score != null && Pattern.compile("^\\d+$").matcher(score).matches()) { + if (score != null && NUM.matcher(score).matches()) { int value = Integer.parseInt(score); return value > 0 && value <= PropertiesUtil.getIntValue("score.max"); } else { diff --git a/app/src/main/res/layout/main/layout/info/layout/info_fragment.xml b/app/src/main/res/layout/main/layout/info/layout/info_fragment.xml index 88c3ddb..d535be3 100644 --- a/app/src/main/res/layout/main/layout/info/layout/info_fragment.xml +++ b/app/src/main/res/layout/main/layout/info/layout/info_fragment.xml @@ -37,7 +37,7 @@ android:layout_height="wrap_content" android:layout_marginStart="32dp" android:layout_marginTop="@dimen/size_50" - android:textSize="24sp" + android:textSize="18sp" app:layout_constraintStart_toEndOf="@id/headimg" app:layout_constraintTop_toTopOf="parent" /> @@ -47,7 +47,7 @@ android:layout_height="wrap_content" android:layout_marginStart="32dp" android:layout_marginTop="@dimen/size_50" - android:textSize="24sp" + android:textSize="18sp" app:layout_constraintStart_toEndOf="@id/headimg" app:layout_constraintTop_toBottomOf="@id/nickname" /> @@ -73,7 +73,7 @@ android:id="@+id/recentPosts" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_weight="1" + android:layout_weight="1.5" android:background="@drawable/border" android:gravity="center" android:textSize="18sp" /> @@ -96,7 +96,7 @@ not permissions click to set headimg upload img.... + compress img… \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 825c465..64c4cdf 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -236,4 +236,5 @@ 你当前没有文件读写权限执行此操作 点击上方设置头像 上传头像中。。。。 + 压缩图片中。。。 \ No newline at end of file diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml index acd0802..204c8f8 100644 --- a/app/src/main/res/values/integers.xml +++ b/app/src/main/res/values/integers.xml @@ -3,4 +3,5 @@ 200 10 100 + 50 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 65cef66..55b629e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -237,6 +237,7 @@ not permissions click to set headimg upload img.... + compress img… diff --git a/app/src/main/res/xml/provider_paths.xml b/app/src/main/res/xml/provider_paths.xml new file mode 100644 index 0000000..a075ef9 --- /dev/null +++ b/app/src/main/res/xml/provider_paths.xml @@ -0,0 +1,6 @@ + + + +