Skip to content

Commit

Permalink
added force tablet mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlbo committed Oct 2, 2023
1 parent 78dca26 commit 1117fc1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/ru/vtosters/hooks/TabletHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.vtosters.hooks;

import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.utils.AndroidUtils;

public class TabletHook {
public static boolean hook() {
return AndroidUtils.isTablet() && !Preferences.getBoolValue("disableForceTabletMode", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ private void prefs() {
findPreference("showmenu").setVisible(false);
}

var tablet = findPreference("disableForceTabletMode");
tablet.setVisible(AndroidUtils.isTablet());
tablet.setOnPreferenceClickListener(preference -> {
LifecycleUtils.restartApplicationWithTimer();
return true;
});

findPreference("customrounding").setOnPreferenceClickListener(preference -> {
RoundingSeekbarDialog.dialog(getContext());
return true;
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/ru/vtosters/lite/utils/AndroidUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.core.app.NotificationManagerCompat;
import com.vk.core.util.Screen;
import com.vk.core.util.ToastUtils;
import com.vtosters.lite.general.fragments.WebViewFragment;
import ru.vtosters.hooks.other.Preferences;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -32,6 +33,12 @@

public class AndroidUtils {
private static final String ALLOWED_CHARACTERS = "0123456789qwertyuiopasdfghjklzxcvbnm";
public enum ScreenSize {
small,
normal,
large,
xlarge
}

public static boolean isDebuggable() {
return 0 != (AndroidUtils.getGlobalContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE);
Expand All @@ -44,7 +51,8 @@ public static boolean isAdbOrDeveloperOptionsEnabled(ContentResolver contentReso
}

public static boolean isTablet() {
return Screen.l(getGlobalContext());
String string = getGlobalContext().getResources().getString(b.h.g.d.screen_size);
return TextUtils.equals(string, ScreenSize.large.name()) || TextUtils.equals(string, ScreenSize.xlarge.name());
}

@NonNull
Expand Down
5 changes: 5 additions & 0 deletions smali/res/xml/preferences_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
android:key="pollresults"
android:summary="@string/pollresults_summ"
android:title="@string/pollresults_title"/>
<com.vtosters.lite.ui.MaterialSwitchPreference
android:defaultValue="false"
android:key="disableForceTabletMode"
android:summary="Отключает интерфейс для планшетов и возвращает докбар"
android:title="Отключить режим планшета"/>
<com.vtosters.lite.ui.MaterialSwitchPreference
android:defaultValue="false"
android:key="friendsblock"
Expand Down
23 changes: 1 addition & 22 deletions smali/smali_classes2/com/vk/core/util/Screen.smali
Original file line number Diff line number Diff line change
Expand Up @@ -1088,31 +1088,10 @@
.end annotation
.end param

.line 1
invoke-static {p0}, Lcom/vk/core/util/Screen;->f(Landroid/content/Context;)Lcom/vk/core/util/Screen$ScreenSize;

move-result-object p0

invoke-virtual {p0}, Ljava/lang/Enum;->ordinal()I
invoke-static {}, Lru/vtosters/hooks/TabletHook;->hook()Z

move-result p0

sget-object v0, Lcom/vk/core/util/Screen$ScreenSize;->normal:Lcom/vk/core/util/Screen$ScreenSize;

invoke-virtual {v0}, Ljava/lang/Enum;->ordinal()I

move-result v0

if-le p0, v0, :cond_0

const/4 p0, 0x1

goto :goto_0

:cond_0
const/4 p0, 0x0

:goto_0
return p0
.end method

Expand Down

0 comments on commit 1117fc1

Please sign in to comment.