Wallpaper in msg

Upgraded dialogs opening
This commit is contained in:
gdlbo
2022-07-11 01:29:55 +03:00
parent 84c194d318
commit 1afa317e7b
9 changed files with 539 additions and 10 deletions
@@ -5,6 +5,7 @@ import static ru.vtosters.lite.f0x1d.VTVerifications.vtverif;
import static ru.vtosters.lite.ui.vkui.VBListBuilder.VBListItem;
import static ru.vtosters.lite.ui.vkui.VBListBuilder.buildListOf;
import static ru.vtosters.lite.ui.vkui.VBottomSheetBuilder.VBSContent;
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaper;
import static ru.vtosters.lite.utils.About.getBuildNumber;
import static ru.vtosters.lite.utils.About.getCommitLink;
import static ru.vtosters.lite.utils.CacheUtils.humanReadableByteCountBin;
@@ -64,6 +65,7 @@ import ru.vtosters.lite.ui.fragments.dockbar.DockBarFragment;
import ru.vtosters.lite.ui.fragments.dockbar.DockBarManager;
import ru.vtosters.lite.ui.fragments.tgstickers.StickersFragment;
import ru.vtosters.lite.ui.vkui.VBottomSheetBuilder;
import ru.vtosters.lite.ui.wallpapers.WallpaperMenuFragment;
import ru.vtosters.lite.utils.CacheUtils;
import ru.vtosters.lite.utils.Globals;
import ru.vtosters.lite.utils.SSFS;
@@ -129,6 +131,18 @@ public class VTSettings extends MaterialPreferenceToolbarFragment{
return Globals.getString("autoclearcachesumm") + " " + humanReadableByteCountBin(CacheUtils.getInstance().size);
}
public static String getWallpapersumm(){
if(disableSettingsSumms()) return null;
var hasWP = getWallpaper() != null;
if(hasWP){
return "Фон: " + "Установлен";
}
return "Фон: " + "Не установлен";
}
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
@@ -325,6 +339,14 @@ public class VTSettings extends MaterialPreferenceToolbarFragment{
return false;
});
PreferencesUtil.addPreference(this, "", "Обои в сообщениях", getWallpapersumm(), "ic_media_outline_28", preference -> {
Context context = getContext();
Intent a2 = new Navigator(WallpaperMenuFragment.class).b(context);
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(a2);
return false;
});
PreferencesUtil.addPreference(this, "", Globals.getString("vtlmessages"), msgsumm, !DoNotUseOldIcons() ? "ic_message_24" : "ic_message_outline_28", preference -> {
Context context = getContext();
Intent a2 = new Navigator(MessagesFragment.class).b(context);
@@ -0,0 +1,135 @@
package ru.vtosters.lite.ui.wallpapers;
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getDimmingSummary;
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getRadiusSummary;
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaperFile;
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.removeWallpaper;
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.requestUpdateWallpaper;
import static ru.vtosters.lite.utils.Globals.edit;
import static ru.vtosters.lite.utils.Globals.getIdentifier;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import ru.vtosters.lite.ui.PreferencesUtil;
public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment{
private WallpaperPreferences mWPPreviewPref;
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
int vtosterXml = getIdentifier("empty", "xml");
addPreferencesFromResource(vtosterXml);
PreferencesUtil.addPreferenceCategory(this, "Предпросмотр");
mWPPreviewPref = new WallpaperPreferences(getContext());
mWPPreviewPref.setIcon(null);
mWPPreviewPref.setIconSpaceReserved(false);
getPreferenceScreen().addPreference(mWPPreviewPref);
PreferencesUtil.addPreference(this, "wp_set", "Выбрать обои", "из галереи", "ic_picture_outline_28", preference -> {
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 1488);
return true;
});
PreferencesUtil.addPreference(this, "wp_clear", "Удалить обои", "", "ic_delete_outline_28", preference -> {
removeWallpaper();
requestUpdateWallpaper();
mWPPreviewPref.redraw();
return true;
});
PreferencesUtil.addPreferenceCategory(this, "Параметры");
PreferencesUtil.addListPreference(this, "msg_blur_radius", "disabled", "Размытие фона сообщений", new CharSequence[]{
"Отключено", "Низкое (15px)", "Среднее (25px)", "Высокое (50px)"
}, new String[]{
"disabled", "low", "med", "high"
});
PreferencesUtil.addListPreference(this, "msg_dim", "off", "Затемнение изображения", new CharSequence[]{
"Отключено", "Затемнить", "Осветлить"
}, new String[]{
"off", "dim_black", "dim_white"
});
ListPreference blur = (ListPreference) findPreference("msg_blur_radius");
ListPreference dim = (ListPreference) findPreference("msg_dim");
blur.setSummary(getRadiusSummary());
dim.setSummary(getDimmingSummary());
blur.setOnPreferenceChangeListener((preference, o) -> {
edit().putString("msg_blur_radius", (String) o).apply();
preference.setSummary(getRadiusSummary());
requestUpdateWallpaper();
mWPPreviewPref.redraw();
return true;
});
dim.setOnPreferenceChangeListener((preference, o) -> {
edit().putString("msg_dim", (String) o).apply();
preference.setSummary(getDimmingSummary());
requestUpdateWallpaper();
mWPPreviewPref.redraw();
return true;
});
}
@Override
public void onActivityResult(int i, int i1, @Nullable Intent intent){
super.onActivityResult(i, i1, intent);
if(intent == null || intent.getData() == null)
return;
try {
InputStream fileInputStream = requireActivity().getContentResolver().openInputStream(intent.getData());
OutputStream outputStream = new FileOutputStream(getWallpaperFile());
copyStream(fileInputStream, outputStream);
requestUpdateWallpaper();
if(i == 1488){
mWPPreviewPref.redraw();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(requireActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}
public static void copyStream(InputStream copyFrom, OutputStream copyTo) throws IOException{
byte[] buffer = new byte[1024];
int length;
while ((length = copyFrom.read(buffer)) > 0) {
copyTo.write(buffer, 0, length);
}
copyTo.flush();
copyTo.close();
copyFrom.close();
}
@Override
public int T4(){
return getIdentifier("vtltgs", "string");
}
}
@@ -0,0 +1,170 @@
package ru.vtosters.lite.ui.wallpapers;
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaper;
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaperFile;
import static ru.vtosters.lite.utils.Globals.convertDpToPixel;
import static ru.vtosters.lite.utils.Globals.getIdentifier;
import static ru.vtosters.lite.utils.Themes.getSTextAttr;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import ru.vtosters.lite.ui.PreferencesUtil;
public class WallpaperPreferences extends Preference{
private final Executor mExecutor = Executors.newSingleThreadExecutor();
RecyclerView preview;
ImageView bg;
private Handler mUIHandler;
public WallpaperPreferences(Context context){
this(context, null, -1, -1);
}
public WallpaperPreferences(Context context, AttributeSet attributeSet){
this(context, attributeSet, -1, -1);
}
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr){
this(context, attributeSet, defStyleAttr, -1);
}
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr, int i1){
super(context, attributeSet, defStyleAttr, i1);
setLayoutResource(getIdentifier("wppreview", "layout"));
}
public static int getMsgInColor(Context ctx){
TypedValue typedValue = new TypedValue();
ctx.getTheme().resolveAttribute(getIdentifier("im_bubble_incoming", "attr"), typedValue, true);
return typedValue.data;
}
public static int getMsgOutColor(Context ctx){
TypedValue typedValue = new TypedValue();
ctx.getTheme().resolveAttribute(getIdentifier("im_bubble_outgoing", "attr"), typedValue, true);
return typedValue.data;
}
public static int getSTextColor(Context ctx){
TypedValue typedValue = new TypedValue();
ctx.getTheme().resolveAttribute(getSTextAttr(), typedValue, true);
return typedValue.data;
}
@Override
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder){
super.onBindViewHolder(preferenceViewHolder);
preferenceViewHolder.itemView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, convertDpToPixel(220)));
preferenceViewHolder.itemView.setPadding(0, 0, 0, 0);
preview = (RecyclerView) preferenceViewHolder.findViewById(getIdentifier("install_btn_container", "id"));
preview.setPadding(0, convertDpToPixel(8), 0, 0);
preview.setLayoutManager(new LinearLayoutManager(getContext()));
preview.setAdapter(new PreviewAdapter());
preview.setClickable(false);
preview.setFocusable(false);
mUIHandler = new Handler();
bg = (ImageView) preferenceViewHolder.findViewById(getIdentifier("author", "id"));
requestBg();
}
private void requestBg(){
mExecutor.execute(() -> {
final Drawable drawable = getWallpaper();
mUIHandler.post(() -> {
if(drawable != null && getWallpaperFile().exists())
bg.setImageDrawable(drawable);
else
bg.setImageDrawable(null);
});
});
}
void redraw(){
preview.getAdapter().notifyDataSetChanged();
requestBg();
}
private static class PreviewAdapter extends RecyclerView.Adapter<PreviewAdapter.PreviewVH>{
private final CharSequence[] previews = new CharSequence[]{
" Привет ", " Привет ", " Ты кто? "
};
private final boolean[] isOut = new boolean[]{
false, true, false
};
@Override
public int getItemCount(){
return previews.length;
}
@Override
public void onBindViewHolder(@NonNull PreviewAdapter.PreviewVH previewVH, int i){
TextView bubble = previewVH.itemView.findViewById(getIdentifier("author", "id"));
bubble.setText(previews[previewVH.getAdapterPosition()]);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
if(isOut[previewVH.getAdapterPosition()]){
params.addRule(RelativeLayout.ALIGN_PARENT_END);
bubble.setPadding(convertDpToPixel(16), convertDpToPixel(16), convertDpToPixel(24), 0);
bubble.setBackgroundResource(getIdentifier("vkim_msg_new_out_light_full", "drawable"));
bubble.setBackgroundTintList(ColorStateList.valueOf(getMsgOutColor(previewVH.itemView.getContext())));
} else {
params.addRule(RelativeLayout.ALIGN_PARENT_START);
bubble.setPadding(convertDpToPixel(24), convertDpToPixel(16), convertDpToPixel(16), 0);
bubble.setBackgroundResource(getIdentifier("vkim_msg_new_in_light_full", "drawable"));
bubble.setBackgroundTintList(ColorStateList.valueOf(getMsgInColor(previewVH.itemView.getContext())));
}
bubble.setTextColor(PreferencesUtil.getTextColor(previewVH.itemView.getContext()));
bubble.setLayoutParams(params);
}
@NonNull
@Override
public PreviewAdapter.PreviewVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i){
Context ctx = viewGroup.getContext();
RelativeLayout root = new RelativeLayout(ctx);
root.setLayoutParams(new RecyclerView.LayoutParams(
RecyclerView.LayoutParams.MATCH_PARENT,
RecyclerView.LayoutParams.MATCH_PARENT));
TextView bubble = new TextView(ctx);
bubble.setId(getIdentifier("author", "id"));
root.addView(bubble);
return new PreviewVH(root);
}
private static class PreviewVH extends RecyclerView.ViewHolder{
public PreviewVH(@NonNull View view){
super(view);
}
}
}
}
@@ -0,0 +1,161 @@
package ru.vtosters.lite.ui.wallpapers;
import static com.vk.im.engine.h.im_bg_chat;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Globals.getIdentifier;
import static ru.vtosters.lite.utils.Globals.getPreferences;
import static ru.vtosters.lite.utils.Globals.getResources;
import static ru.vtosters.lite.utils.Globals.scaleCenterCrop;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import com.vk.im.ui.views.FrescoImageView;
import com.vk.medianative.MediaNative;
import java.io.File;
public class WallpapersHooks{
private static File mWallpaperFile;
private static Drawable mWallpaper;
private static boolean mUpdateWallpaperRequested = true;
public static File getWallpaperFile(){
return mWallpaperFile == null ? mWallpaperFile = new File(getContext().getFilesDir(), "wallpaper.png") : mWallpaperFile;
}
public static void setBg(View view){
if(getWallpaper() != null){
((ImageView) view).setImageDrawable(getWallpaper()); // set picture to background
return;
}
((ImageView) view).setColorFilter(im_bg_chat); // set default bg color
}
public static String getWallpaperUrl(){
if(getWallpaperFile().exists())
return getWallpaperFile().getAbsolutePath();
else
return "default";
}
public static Drawable getWallpaper(){
if(mWallpaper == null || mUpdateWallpaperRequested){
if(!getPreferences().getString("msg_blur_radius", "disabled").equals("disabled")){
mWallpaper = getBlurredWallpaper(Drawable.createFromPath(getWallpaperUrl()), getRadius());
} else {
mWallpaper = Drawable.createFromPath(getWallpaperUrl());
}
if(!getPreferences().getString("msg_dim", "off").equals("off")){
mWallpaper = getDimmed(mWallpaper);
}
mUpdateWallpaperRequested = false;
}
return mWallpaper;
}
public static void requestUpdateWallpaper(){
mUpdateWallpaperRequested = true;
}
private static int getRadius(){
String radius = getPreferences().getString("msg_blur_radius", "disabled");
switch(radius) {
case "low":
return 15;
case "med":
return 25;
default:
return 50;
}
}
public static String getRadiusSummary(){
String radius = getPreferences().getString("msg_blur_radius", "disabled");
switch(radius) {
case "disabled":
return "Отключено";
case "low":
return "Низкое (15px)";
case "med":
return "Среднее (25px)";
default:
return "Высокое (50px)";
}
}
public static String getDimmingSummary(){
String radius = getPreferences().getString("msg_dim", "disabled");
switch(radius) {
case "off":
return "Отключено";
case "dim_black":
return "Затемнить";
case "dim_white":
return "Осветлить";
default:
return "OwO";
}
}
public static Drawable getBlurredWallpaper(Drawable orig, int radius){
try {
if(orig == null) return null;
if(!(orig instanceof BitmapDrawable)) return orig; // we need only BitmapDrawable
Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
MediaNative.blurBitmap(instance, radius);
return new BitmapDrawable(getResources(), instance);
} catch (Exception e) {
e.printStackTrace();
return orig;
}
}
public static Drawable getDimmed(Drawable orig){
if(orig == null) return null;
if(!(orig instanceof BitmapDrawable)) return orig; // we need only BitmapDrawable
Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
String radius = getPreferences().getString("msg_dim", "disabled");
switch(radius) {
case "dim_black":
instance = darken(instance);
case "dim_white":
instance = lighten(instance);
}
return new BitmapDrawable(getResources(), instance);
}
private static Bitmap darken(Bitmap bm){
Canvas canvas = new Canvas(bm);
Paint p = new Paint(Color.RED);
ColorFilter filter = new LightingColorFilter(0xFF7F7F7F, 0x00000000); // darken
p.setColorFilter(filter);
canvas.drawBitmap(bm, new Matrix(), p);
return bm;
}
private static Bitmap lighten(Bitmap bm){
Canvas canvas = new Canvas(bm);
Paint p = new Paint(Color.RED);
ColorFilter filter = new LightingColorFilter(0xFFFFFFFF, 0x00222222); // lighten
p.setColorFilter(filter);
canvas.drawBitmap(bm, new Matrix(), p);
return bm;
}
public static void removeWallpaper(){
getWallpaperFile().delete();
}
}
@@ -25,6 +25,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
@@ -158,6 +159,29 @@ public class Globals{
return userProfile.b;
} // UserId Profile via userProfile
public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
float xScale = (float) newWidth / sourceWidth;
float yScale = (float) newHeight / sourceHeight;
float scale = Math.max(xScale, yScale);
float scaledWidth = scale * sourceWidth;
float scaledHeight = scale * sourceHeight;
float left = (newWidth - scaledWidth) / 2;
float top = (newHeight - scaledHeight) / 2;
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
Canvas canvas = new Canvas(dest);
canvas.drawBitmap(source, null, targetRect, null);
return dest;
}
public static String getUserFirstName(UserProfile userProfile){
return userProfile.c;
}
+2 -2
View File
@@ -7,11 +7,11 @@
android:clipChildren="true"
android:clipToPadding="true">
<com.vk.im.ui.views.FrescoImageView
<ImageView
android:id="@id/dialog_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:vkim_scaleType="center_crop" />
android:scaleType="centerCrop" />
<ViewStub
android:id="@id/dialog_header_container_stub"
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp">
<ImageView
android:id="@id/author"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<androidx.recyclerview.widget.RecyclerView
android:id="@id/install_btn_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
@@ -427,6 +427,12 @@
.method public final c()Ljava/lang/String;
.locals 3
invoke-static {}, Lru/vtosters/lite/ui/wallpapers/WallpapersHooks;->getWallpaperUrl()Ljava/lang/String;
move-result-object v0
return-object v0
.line 1
invoke-direct {p0}, Lcom/vk/im/ui/ImUiPrefs;->k()Landroid/content/SharedPreferences;
@@ -768,7 +768,9 @@
.end method
.method private final X4()V
.locals 7
.locals 8
return-void
.line 1
sget-object v0, Lcom/vk/im/ui/ImUiPrefs;->g:Lcom/vk/im/ui/ImUiPrefs;
@@ -5155,13 +5157,7 @@
move-result-object v1
const-string v2, "view.findViewById(R.id.dialog_background)"
invoke-static {v1, v2}, Lkotlin/jvm/internal/Intrinsics;->a(Ljava/lang/Object;Ljava/lang/String;)V
check-cast v1, Lcom/vk/im/ui/views/FrescoImageView;
iput-object v1, v0, Lcom/vk/im/ui/fragments/ChatFragment;->k0:Lcom/vk/im/ui/views/FrescoImageView;
invoke-static {v1}, Lru/vtosters/lite/ui/wallpapers/WallpapersHooks;->setBg(Landroid/view/View;)V
.line 69
sget v1, Lcom/vk/im/ui/h;->sticker_bar_container_stub:I