added "likes on right" displaying mode for posts and viewers

This commit is contained in:
Vologhat
2022-08-01 13:33:58 +03:00
parent 59c8be9ac2
commit 186c1f80e6
7 changed files with 82 additions and 0 deletions
@@ -0,0 +1,67 @@
package ru.vtosters.lite.hooks;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import androidx.recyclerview.widget.RecyclerView;
import com.vk.newsfeed.holders.BaseFooterHolder;
import com.vtosters.lite.R;
import ru.vtosters.lite.utils.Preferences;
public class PostViewHook {
/**
* For displaying child elements with custom direction in rtl container we should remove their, set layout direction and add again */
private static void saveChildDirectionForRlt(ViewGroup container) {
var children = new View[container.getChildCount()];
for (int i = 0; i < container.getChildCount(); i++) {
var child = container.getChildAt(i);
child.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
children[i] = child;
}
container.removeAllViews();
for (View child : children) {
container.addView(child);
}
container.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
// res/layout/likes_panel.xml
public static void injectBaseFooterHolder(BaseFooterHolder baseFooterHolder) {
if (!Preferences.isLikesOnRightEnabled())
return;
try {
var container = (ViewGroup) ((RecyclerView.ViewHolder) baseFooterHolder).itemView;
saveChildDirectionForRlt((ViewGroup) container.getChildAt(1));
} catch (Exception e) {
e.printStackTrace();
}
}
// res/layout/photo_viewer_bottom.xml
public static void injectPhotoViewer(View container) {
if (!Preferences.isLikesOnRightEnabled())
return;
try {
var bottomPanel = (ViewGroup) container.findViewById(R.id.photo_viewer_bottom_panel);
saveChildDirectionForRlt(bottomPanel);
} catch (Exception e) {
e.printStackTrace();
}
}
// res/layout/video_bottom_view.xml
public static void injectVideoView(RelativeLayout container) {
if (!Preferences.isLikesOnRightEnabled())
return;
try {
var bottomBar = (ViewGroup) container.findViewById(R.id.bottom_bar);
saveChildDirectionForRlt(bottomBar);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -20,6 +20,7 @@ public class InterfaceFragment extends MaterialPreferenceToolbarFragment {
private void prefs() {
findPreference("stories").setOnPreferenceClickListener(new restart());
findPreference("swipe").setOnPreferenceClickListener(new restart());
findPreference("is_likes_on_right").setOnPreferenceClickListener(new restart());
}
public boolean restart(Preference preference) {
@@ -356,6 +356,10 @@ public class Preferences {
return isPrometheus(AccountManagerUtils.getUserId());
}
public static boolean isLikesOnRightEnabled() {
return getBoolValue("is_likes_on_right", false);
}
public static long getSizeForDelete() {
switch (getPrefsValue("clearcache")) {
case "100mb":
+4
View File
@@ -15,6 +15,10 @@
android:key="whatsnew"
android:summary="Блок написания поста в ленте"
android:title="Показывать блок поста" />
<com.vtosters.lite.ui.MaterialSwitchPreference
android:defaultValue="false"
android:key="is_likes_on_right"
android:title="Показ лайков в посте справа" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/interfaceglobal">
<com.vtosters.lite.ui.SummaryListPreference
@@ -106,6 +106,8 @@
invoke-virtual {p2, p3, p0, v0}, Landroid/view/LayoutInflater;->inflate(ILandroid/view/ViewGroup;Z)Landroid/view/View;
invoke-static/range {p0 .. p0}, Lru/vtosters/lite/hooks/PostViewHook;->injectVideoView(Landroid/widget/RelativeLayout;)V
.line 5
sget p2, Lcom/vk/libvideo/g;->subtitle:I
@@ -62,6 +62,8 @@
.line 1
invoke-direct {p0, p1, p2}, Lcom/vk/newsfeed/holders/BaseNewsEntryHolder;-><init>(ILandroid/view/ViewGroup;)V
invoke-static/range {p0 .. p0}, Lru/vtosters/lite/hooks/PostViewHook;->injectBaseFooterHolder(Lcom/vk/newsfeed/holders/BaseFooterHolder;)V
.line 2
iget-object p1, p0, Landroidx/recyclerview/widget/RecyclerView$ViewHolder;->itemView:Landroid/view/View;
@@ -102,6 +102,8 @@
move-result-object v0
invoke-static/range {v0 .. v0}, Lru/vtosters/lite/hooks/PostViewHook;->injectPhotoViewer(Landroid/view/View;)V
const-string v1, "LayoutInflater.from(cont\u2026hoto_viewer_bottom, null)"
invoke-static {v0, v1}, Lkotlin/jvm/internal/Intrinsics;->a(Ljava/lang/Object;Ljava/lang/String;)V