updated and refactored vt settings
This commit is contained in:
@@ -5,6 +5,7 @@ import android.app.Activity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.hooks.other.ThemesUtils;
|
||||
import ru.vtosters.lite.downloaders.OTADownloader;
|
||||
@@ -17,22 +18,26 @@ public class OTADialog extends ModalBottomSheetWrapper<OTADialog> implements OTA
|
||||
|
||||
private final OTAUtils mHelper;
|
||||
|
||||
public OTADialog(Activity activity) {
|
||||
public OTADialog(Activity activity, boolean isManualCheck) {
|
||||
super(activity);
|
||||
mActivity = activity;
|
||||
|
||||
mHelper = new OTAUtils(this);
|
||||
mHelper.loadData();
|
||||
mHelper.loadData(isManualCheck);
|
||||
}
|
||||
|
||||
public static void checkUpdates(Activity activity) {
|
||||
new OTADialog(activity);
|
||||
new OTADialog(activity, false);
|
||||
}
|
||||
|
||||
public static void checkUpdatesManual(Activity activity) {
|
||||
new OTADialog(activity, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateApplied() {
|
||||
public void onUpdateApplied(boolean isManualCheck) {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
// Toast.makeText(mActivity, "Обновления найдены", Toast.LENGTH_SHORT).show();
|
||||
if (isManualCheck) Toast.makeText(mActivity, "Обновления найдены", Toast.LENGTH_SHORT).show();
|
||||
setTitle(mActivity.getString(R.string.newversion) + " " + mHelper.getNewVersionName())
|
||||
.setView(makeUpdateInfoView(mHelper.getUpdateDescription()))
|
||||
.setPositiveButton(mActivity.getString(R.string.updateanddownload), () -> {
|
||||
@@ -57,9 +62,18 @@ public class OTADialog extends ModalBottomSheetWrapper<OTADialog> implements OTA
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateCanceled() {
|
||||
// mActivity.runOnUiThread(() -> {
|
||||
// // Toast.makeText(mActivity, "Обновлений не найдено", Toast.LENGTH_SHORT).show();
|
||||
// });
|
||||
public void onUpdateLatest(boolean isManualCheck) {
|
||||
if (isManualCheck) {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
Toast.makeText(mActivity, "У вас установлена последняя версия приложения", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateError() {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
Toast.makeText(mActivity, "Ошибка проверки обновления", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.*;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.preference.Preference;
|
||||
import com.aefyr.tsg.g2.TelegramStickersService;
|
||||
import com.vk.about.AboutAppFragment;
|
||||
import com.vk.balance.BalanceFragment;
|
||||
import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vk.identity.fragments.IdentityListFragment;
|
||||
import com.vk.medianative.MediaImageEncoder;
|
||||
import com.vk.notifications.settings.NotificationsSettingsFragment;
|
||||
@@ -45,16 +46,14 @@ import ru.vtosters.lite.utils.*;
|
||||
import java.util.Locale;
|
||||
|
||||
public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
public static String ACTION_INVALIDATE_TGS_COUNT = "com.vtosters.lite.intent.action.INVALIDATE_TGS_COUNT";
|
||||
|
||||
final static public String ACTION_INVALIDATE_TGS_COUNT="com.vtosters.lite.intent.action.INVALIDATE_TGS_COUNT";
|
||||
|
||||
final BroadcastReceiver mTgsReceiver=new BroadcastReceiver()
|
||||
{
|
||||
BroadcastReceiver mTgsReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
if(ACTION_INVALIDATE_TGS_COUNT.equals(intent.getAction()))
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (ACTION_INVALIDATE_TGS_COUNT.equals(intent.getAction())) {
|
||||
findPreference("tgs_stickers").setSummary(getTGSsumm());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -90,12 +89,13 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
ThemesUtils.setTheme(isDarkTheme ? ThemesUtils.getDarkTheme() : ThemesUtils.getLightTheme(), requireActivity(), true);
|
||||
}
|
||||
|
||||
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
requireContext().registerReceiver(mTgsReceiver,new IntentFilter(ACTION_INVALIDATE_TGS_COUNT));
|
||||
requireContext().registerReceiver(mTgsReceiver, new IntentFilter(ACTION_INVALIDATE_TGS_COUNT));
|
||||
|
||||
this.addPreferencesFromResource(R.xml.empty);
|
||||
|
||||
@@ -112,6 +112,7 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
try {
|
||||
VKAuth.a("logout", false);
|
||||
} catch (Exception ignored) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
Intent intent = new Intent(requireContext(), MainActivity.class)
|
||||
@@ -159,8 +160,8 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
AndroidUtils.sendToast(AndroidUtils.getString("systemtheme_enabled"));
|
||||
return false;
|
||||
}
|
||||
final MaterialSwitchPreference switchPreference = (MaterialSwitchPreference) preference;
|
||||
final boolean isDarkTheme = !switchPreference.isChecked();
|
||||
MaterialSwitchPreference switchPreference = (MaterialSwitchPreference) preference;
|
||||
boolean isDarkTheme = !switchPreference.isChecked();
|
||||
switchTheme(isDarkTheme);
|
||||
return true;
|
||||
}
|
||||
@@ -175,7 +176,7 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
R.drawable.ic_palette_outline_28,
|
||||
Preferences.systemtheme(),
|
||||
(preference, o) -> {
|
||||
Preferences.getPreferences().edit().putBoolean("system_theme", (boolean) o).commit();
|
||||
Preferences.getPreferences().edit().putBoolean("system_theme", (boolean) o).apply();
|
||||
SystemThemeChangerHook.onThemeChanged(requireActivity().getResources().getConfiguration());
|
||||
return true;
|
||||
}
|
||||
@@ -480,14 +481,7 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
AndroidUtils.getString("currentLanguage") + " " + AndroidUtils.upString(Locale.getDefault().getDisplayLanguage()),
|
||||
R.drawable.ic_globe_outline_28,
|
||||
preference -> {
|
||||
try {
|
||||
Intent intent = new Intent("android.settings.APP_LOCALE_SETTINGS", Uri.parse("package:" + AndroidUtils.getPackageName()));
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AndroidUtils.sendToast("Ваша система не поддерживает смену языка приложения");
|
||||
}
|
||||
|
||||
startActivity(new Intent("android.settings.APP_LOCALE_SETTINGS", Uri.parse("package:" + AndroidUtils.getPackageName())));
|
||||
return false;
|
||||
}
|
||||
);
|
||||
@@ -519,18 +513,57 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
}
|
||||
);
|
||||
|
||||
if (AndroidUtils.isAdbOrDeveloperOptionsEnabled(requireContext().getContentResolver())) {
|
||||
PreferenceFragmentUtils.addPreference(
|
||||
getPreferenceScreen(),
|
||||
"",
|
||||
requireContext().getString(R.string.opencommit),
|
||||
"",
|
||||
R.drawable.ic_link_outline_28,
|
||||
preference -> {
|
||||
requireContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(AboutHook.getCommitLink())));
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
PreferenceFragmentUtils.addPreference(
|
||||
getPreferenceScreen(),
|
||||
"",
|
||||
requireContext().getString(R.string.opencommit),
|
||||
"",
|
||||
R.drawable.ic_link_outline_28,
|
||||
"Наши чаты",
|
||||
"Активные чаты по обсуждению модификации и многому другому",
|
||||
R.drawable.ic_message_outline_28,
|
||||
preference -> {
|
||||
requireContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(AboutHook.getCommitLink())));
|
||||
var args = new Bundle();
|
||||
var dialog = new AboutInformation();
|
||||
|
||||
args.putString("vk_link", "https://vk.me/join/jKE1bIZczHTF2mLkuoiQcd0qIBYgHuGFPRA=");
|
||||
args.putString("tg_link", "https://t.me/vtosterschat");
|
||||
|
||||
dialog.setArguments(args);
|
||||
dialog.show(requireFragmentManager(), "");
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
PreferenceFragmentUtils.addPreference(
|
||||
getPreferenceScreen(),
|
||||
"",
|
||||
"Наши сообщества",
|
||||
"Самая свежая информация об обновлениях и не только!",
|
||||
R.drawable.users_3_outline_28,
|
||||
preference -> {
|
||||
var args = new Bundle();
|
||||
var dialog = new AboutInformation();
|
||||
|
||||
args.putString("vk_link", "https://vk.com/vtosters_official");
|
||||
args.putString("tg_link", "https://t.me/vtosters");
|
||||
|
||||
dialog.setArguments(args);
|
||||
dialog.show(requireFragmentManager(), "");
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
PreferenceFragmentUtils.addPreference(
|
||||
getPreferenceScreen(),
|
||||
@@ -566,7 +599,7 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
"",
|
||||
R.drawable.ic_download_outline_28,
|
||||
preference -> {
|
||||
OTADialog.checkUpdates(getActivity());
|
||||
OTADialog.checkUpdatesManual(getActivity());
|
||||
return false;
|
||||
}
|
||||
);
|
||||
@@ -574,8 +607,7 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
public void onDestroy() {
|
||||
requireContext().unregisterReceiver(mTgsReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
@@ -584,4 +616,25 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
|
||||
public int T4() {
|
||||
return R.string.notification_settings;
|
||||
}
|
||||
|
||||
public static class AboutInformation extends DialogFragment {
|
||||
@Override
|
||||
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
|
||||
VkAlertDialog.Builder builder = new VkAlertDialog.Builder(requireActivity());
|
||||
|
||||
String[] items = {AndroidUtils.getString(R.string.app_name_alter), "Telegram"};
|
||||
|
||||
builder.setItems(items, (dialog, which) -> {
|
||||
switch (which) {
|
||||
case 0 ->
|
||||
requireContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(getArguments().getString("vk_link"))));
|
||||
case 1 ->
|
||||
requireContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(getArguments().getString("tg_link"))));
|
||||
}
|
||||
dismiss();
|
||||
});
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -39,6 +40,12 @@ public class AndroidUtils {
|
||||
return 0 != (AndroidUtils.getGlobalContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE);
|
||||
}
|
||||
|
||||
public static boolean isAdbOrDeveloperOptionsEnabled(ContentResolver contentResolver) {
|
||||
int adbEnabled = Settings.Global.getInt(contentResolver, Settings.Global.ADB_ENABLED, 0);
|
||||
int developerOptionsEnabled = Settings.Global.getInt(contentResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
|
||||
return adbEnabled == 1 || developerOptionsEnabled == 1;
|
||||
}
|
||||
|
||||
public static boolean isTablet() {
|
||||
return Screen.l(getGlobalContext());
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ExternalLinkParser {
|
||||
|
||||
parseVKVideo(videoFile, qualities, urls);
|
||||
|
||||
if (urls.size() > 0)
|
||||
if (!urls.isEmpty())
|
||||
if (getBoolValue("maxquality", false) || qualities.size() == 1)
|
||||
startExternalVideo(context, urls.get(0));
|
||||
else
|
||||
|
||||
@@ -22,7 +22,7 @@ public class OTAUtils {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
public void loadData(boolean isManualCheck) {
|
||||
Request release = new Request.a()
|
||||
.b(LATEST_RELEASE_URL)
|
||||
.a();
|
||||
@@ -31,13 +31,13 @@ public class OTAUtils {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d("OTAHelper", "Error while getting latest release info: " + e);
|
||||
mListener.onUpdateCanceled();
|
||||
mListener.onUpdateError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Call call, Response response) throws IOException {
|
||||
try {
|
||||
setData(response);
|
||||
setData(response, isManualCheck);
|
||||
} catch (JSONException | NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class OTAUtils {
|
||||
});
|
||||
}
|
||||
|
||||
void setData(Response response) throws IOException, JSONException {
|
||||
void setData(Response response, boolean isManualCheck) throws IOException, JSONException {
|
||||
mReleaseJson = new JSONObject(response.a().g());
|
||||
|
||||
String tag = mReleaseJson.getString("tag_name");
|
||||
@@ -58,7 +58,7 @@ public class OTAUtils {
|
||||
@Override
|
||||
public void a(Call call, IOException e) {
|
||||
Log.d("OTAHelper", "Error while getting latest commit info: " + e);
|
||||
mListener.onUpdateCanceled();
|
||||
mListener.onUpdateError();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,12 +67,12 @@ public class OTAUtils {
|
||||
mCommitJson = new JSONObject(response.a().g());
|
||||
mCommitSHA = mCommitJson.getJSONObject("object").getString("sha");
|
||||
if (isNewVersion())
|
||||
mListener.onUpdateApplied();
|
||||
mListener.onUpdateApplied(isManualCheck);
|
||||
else
|
||||
mListener.onUpdateCanceled();
|
||||
mListener.onUpdateLatest(isManualCheck);
|
||||
} catch (NullPointerException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
mListener.onUpdateCanceled();
|
||||
mListener.onUpdateError();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -118,9 +118,10 @@ public class OTAUtils {
|
||||
|
||||
public interface OTAListener {
|
||||
|
||||
void onUpdateApplied();
|
||||
void onUpdateApplied(boolean isManualCheck);
|
||||
|
||||
void onUpdateCanceled();
|
||||
void onUpdateError();
|
||||
|
||||
void onUpdateLatest(boolean isManualCheck);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user