Skip to content

Commit

Permalink
fix #1406
Browse files Browse the repository at this point in the history
  • Loading branch information
Vologhat committed Jul 13, 2023
1 parent 66f7ea1 commit 7d36973
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 42 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.os.Build;
import b.h.g.k.VKProgressDialog;
import com.aefyr.tsg.g2.TelegramStickersService;
import com.vk.core.dialogs.alert.VkAlertDialog;
import com.vtosters.lite.R;
import ru.vtosters.hooks.other.Preferences;
Expand Down Expand Up @@ -65,6 +66,8 @@ public static void inject(Activity activity) {
InstallGMS.alert(activity);
DisableBattery.alert(activity);
// VKIDProtection.alert(activity);
//needs to show selected tgs pack count in settings after cold launch
TelegramStickersService.getInstance(activity);
}

private static void updateBinsAndTmpArchive(Activity activity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.vtosters.lite.ui.adapters;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -28,6 +29,7 @@
import ru.vtosters.lite.tgs.TGPref;
import ru.vtosters.lite.tgs.TGRoot;
import ru.vtosters.lite.ui.components.IItemMovingListener;
import ru.vtosters.lite.ui.fragments.VTSettings;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -138,7 +140,11 @@ public void bind(int position) {
});
mName.setText(pack.title);
mSwitch.setChecked(pack.enabled);
mSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> sService.setPackEnabled(pack, isChecked, true));
mSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
sService.setPackEnabled(pack, isChecked, false);
buttonView.getContext().sendBroadcast(new Intent(VTSettings.ACTION_INVALIDATE_TGS_COUNT));
});

mStickersCount.setText(pack.stickersCount + " " + mStickersCount.getContext().getString(R.string.stickerscount));

SwitchHook.setSwitchCompatColors(mSwitch, mSwitch.getContext());
Expand Down
62 changes: 21 additions & 41 deletions app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package ru.vtosters.lite.ui.fragments;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.StringRes;
import androidx.preference.Preference;
import com.aefyr.tsg.g2.TelegramStickersPack;
import com.aefyr.tsg.g2.TelegramStickersService;
import com.vk.about.AboutAppFragment;
import com.vk.balance.BalanceFragment;
Expand Down Expand Up @@ -42,7 +44,19 @@

import java.util.Locale;

public class VTSettings extends TrackedMaterialPreferenceToolbarFragment implements TelegramStickersService.StickersEventsListener {
public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {

final static public String ACTION_INVALIDATE_TGS_COUNT="com.vtosters.lite.intent.action.INVALIDATE_TGS_COUNT";

final BroadcastReceiver mTgsReceiver=new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
if(ACTION_INVALIDATE_TGS_COUNT.equals(intent.getAction()))
findPreference("tgs_stickers").setSummary(getTGSsumm());
}
};

public static String getValAsString(@StringRes int strRes, Boolean value) {
if (value) {
Expand Down Expand Up @@ -76,42 +90,12 @@ private void switchTheme(boolean isDarkTheme) {
ThemesUtils.setTheme(isDarkTheme ? ThemesUtils.getDarkTheme() : ThemesUtils.getLightTheme(), requireActivity(), true);
}

@Override
public void onPackAdded(TelegramStickersPack pack, int atIndex) {

}

@Override
public void onPackRemoved(TelegramStickersPack pack, int atIndex) {

}

@Override
public void onPackChanged(TelegramStickersPack pack, int atIndex) {

}

@Override
public void onPackDownloadError(TelegramStickersPack pack, Exception error) {

}

@Override
public void onActivePacksListChanged() {
findPreference("tgs_stickers").setSummary(getTGSsumm());
}

@Override
public void onInactivePacksListChanged() {

}

@SuppressWarnings("ConstantConditions")
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);

TelegramStickersService.getInstance(requireContext()).addStickersEventsListener(this);
requireContext().registerReceiver(mTgsReceiver,new IntentFilter(ACTION_INVALIDATE_TGS_COUNT));

this.addPreferencesFromResource(R.xml.empty);

Expand Down Expand Up @@ -590,18 +574,14 @@ public void onCreate(Bundle bundle) {
}

@Override
public void onResume() {
super.onResume();
public void onDestroy()
{
requireContext().unregisterReceiver(mTgsReceiver);
super.onDestroy();
}

@Override
public int T4() {
return R.string.notification_settings;
}

@Override
public void onDestroyView() {
super.onDestroyView();
TelegramStickersService.getInstance(requireContext()).removeStickersEventsListener(this);
}
}

0 comments on commit 7d36973

Please sign in to comment.