From 5ac2e79932e026c96ca75bb279cfbfb53f2004de Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Thu, 23 Apr 2020 11:06:45 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8B=8D=E7=85=A7=E5=A4=B4=E5=83=8F=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=BB=8F=E8=BF=87=E7=BC=A9=E6=94=BE=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=86=8D=E5=8E=8B=E7=BC=A9=E4=BD=93=E7=A7=AF=202.=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E5=A4=B4=E5=83=8F=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/pocket/data/model/Forum.java | 17 ++++++++++--- .../pocket/ui/main/ui/forum/ForumPost.java | 9 +++++++ .../main/ui/forum/data/ForumDataActivity.java | 9 +++++++ .../pocket/ui/main/ui/info/InfoFragment.java | 25 +++++++++++++------ app/src/main/res/values-en-rUS/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/integers.xml | 4 +-- app/src/main/res/values/strings.xml | 1 + 8 files changed, 54 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/community/pocket/data/model/Forum.java b/app/src/main/java/com/community/pocket/data/model/Forum.java index 632ff32..7e36e2d 100644 --- a/app/src/main/java/com/community/pocket/data/model/Forum.java +++ b/app/src/main/java/com/community/pocket/data/model/Forum.java @@ -19,13 +19,16 @@ public class Forum { //审核状态 private ForumStatus status; - //其他信息 + //悬赏贴信息 private Active activeDto; - + //投诉贴信息 private Complain complainDto; - + //结算贴信息 private Score score; + //发帖人详情信息 + private MyInfo info; + public Active getActiveDto() { return activeDto; } @@ -113,4 +116,12 @@ public class Forum { public void setScore(Score score) { this.score = score; } + + public MyInfo getInfo() { + return info; + } + + public void setInfo(MyInfo info) { + this.info = info; + } } 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 3dfd03b..b1ef71c 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 @@ -1,11 +1,13 @@ package com.community.pocket.ui.main.ui.forum; import android.content.Intent; +import android.graphics.Bitmap; import android.os.Build; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -13,8 +15,10 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.appcompat.widget.SearchView; import androidx.core.widget.NestedScrollView; +import androidx.lifecycle.MutableLiveData; import com.community.pocket.R; +import com.community.pocket.data.main.info.InfoRequest; import com.community.pocket.data.model.Forum; import com.community.pocket.data.model.Page; import com.community.pocket.ui.BaseFragment; @@ -75,6 +79,11 @@ public abstract class ForumPost extends BaseFragment { author.setVisibility(showAuthor()); author.setText(getString(R.string.poster, forum.getUsername())); + ImageView headimg = childView.findViewById(R.id.headimg); + MutableLiveData liveData = new MutableLiveData<>(); + InfoRequest.getInstance().getImg(liveData, forum.getInfo().getHeadImg()); + liveData.observe(getViewLifecycleOwner(), headimg::setImageBitmap); + TextView postReply = childView.findViewById(R.id.post_reply); postReply.setText(getString(R.string.post_reply, forum.getReply())); TextView time = childView.findViewById(R.id.post_time); 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 9704fee..54a759e 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 @@ -2,6 +2,7 @@ package com.community.pocket.ui.main.ui.forum.data; import android.app.Activity; import android.content.Intent; +import android.graphics.Bitmap; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -11,6 +12,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -19,9 +21,11 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.widget.NestedScrollView; +import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModelProvider; import com.community.pocket.R; +import com.community.pocket.data.main.info.InfoRequest; import com.community.pocket.data.model.Active; import com.community.pocket.data.model.Complain; import com.community.pocket.data.model.Forum; @@ -262,5 +266,10 @@ public class ForumDataActivity extends BaseActivity { tower.setText(getString(R.string.tower, forumContent.getTower())); TextView content = view.findViewById(R.id.content); content.setText(forumContent.getContent()); + ImageView headimg = view.findViewById(R.id.headimg); + MutableLiveData liveData = new MutableLiveData<>(); + InfoRequest.getInstance().getImg(liveData, forumContent.getInfo().getHeadImg()); + liveData.observe(this, headimg::setImageBitmap); + } } 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 427a7a8..b152a89 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 @@ -362,32 +362,40 @@ public class InfoFragment extends BaseFragment { if (picFile.createNewFile()) { - Bitmap bitmap; + Bitmap srcbitmap; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - bitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(requireContext().getContentResolver(), uri)); + srcbitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(requireContext().getContentResolver(), uri)); } else { - bitmap = MediaStore.Images.Media.getBitmap(requireContext().getContentResolver(), uri); + srcbitmap = MediaStore.Images.Media.getBitmap(requireContext().getContentResolver(), uri); } + Context context = requireContext(); - TextView textView = new TextView(getContext()); + + TextView textView = new TextView(context); textView.setTextSize(18); textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); - textView.setText(R.string.compress_img); + textView.setText(R.string.scale_img); AlertDialog uploadDialog = new AlertDialog.Builder(context) .setView(textView).setCancelable(false).show(); + + //缩放图片 + int size = getResources().getInteger(R.integer.photo_size); + Bitmap scalebitmap = Bitmap.createScaledBitmap(srcbitmap, size, size, true); + + compressHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(@NonNull Message msg) { if (msg.what == Response.Result.OK.ordinal()) { - Log.i(InfoFragment.class.getName(), "位图大小:" + bitmap.getByteCount() / 1024 + "KB" + ",压缩大小" + picFile.length() / 1024 + "KB"); + Log.i(InfoFragment.class.getName(), "原图大小:" + srcbitmap.getByteCount() / 1024 / 1024F + "MB,缩放大小:" + scalebitmap.getByteCount() / 1024 / 1024F + "MB,压缩大小:" + picFile.length() / 1024 / 1024F + "MB"); uploadImgHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(@NonNull Message msg) { uploadDialog.dismiss(); if (msg.what == Response.Result.OK.ordinal()) { - headimg.setImageBitmap(bitmap); + headimg.setImageBitmap(scalebitmap); } } }; @@ -400,9 +408,10 @@ public class InfoFragment extends BaseFragment { } }; + textView.setText(R.string.compress_img); new Thread(() -> { try { - bitmap.compress(Bitmap.CompressFormat.PNG, getResources().getInteger(R.integer.photo_quality), new FileOutputStream( + scalebitmap.compress(Bitmap.CompressFormat.PNG, getResources().getInteger(R.integer.photo_quality), new FileOutputStream( picFile)); compressHandler.sendEmptyMessage(Response.Result.OK.ordinal()); } catch (FileNotFoundException e) { diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml index 33acd62..1e4f9ce 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -237,4 +237,5 @@ click to set headimg upload img.... compress img… + scale image... \ 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 64c4cdf..abe1d5d 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -237,4 +237,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 204c8f8..1913c66 100644 --- a/app/src/main/res/values/integers.xml +++ b/app/src/main/res/values/integers.xml @@ -2,6 +2,6 @@ 200 10 - 100 - 50 + 1024 + 100 \ 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 55b629e..dada805 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -238,6 +238,7 @@ click to set headimg upload img.... compress img… + scale image...