Kate Mobile v109.1版本的 MD5 值为:fcd76ded5f363ecbfac46035a4ed2a23
以下内容为反编译后的 Helper.java 源代码,内容仅作参考
package com.perm.kate;
import android.app.Activity;
import android.app.Application;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.text.ClipboardManager;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.common.GoogleApiAvailability;
import com.perm.kate.PhotoSaver;
import com.perm.kate.api.Api;
import com.perm.kate.api.Comment;
import com.perm.kate.api.Photo;
import com.perm.kate.api.ScreenNameInfo;
import com.perm.kate.api.Story;
import com.perm.kate.api.User;
import com.perm.kate.links.VkLink;
import com.perm.kate.links.VkLinkParser;
import com.perm.kate.links.VkLinkType;
import com.perm.kate.photoupload.PhotoChooser;
import com.perm.kate.session.Callback;
import com.perm.kate.session.Session;
import com.perm.utils.InstagramHelper;
import com.perm.utils.Patterns;
import com.perm.utils.ProxyManager;
import com.perm.utils.RepostHelper;
import com.perm.utils.ScaleBitmapDrawable;
import com.perm.utils.SmileHelper;
import com.perm.utils.TimeFix;
import com.perm.utils.UploadProgressListener;
import com.perm.utils.UserAgent;
import com.perm.utils.WrongResponseCodeException;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.SSLException;
import org.json.JSONObject;
public abstract class Helper {
static final NumberFormat nf;
private static long year_start_long;
public static final DateFormat sdf = DateFormat.getDateInstance(1);
public static final DateFormat sdf_date_time = new SimpleDateFormat("dd MMM yyyy H:mm");
public static final DateFormat sdf_date_time_no_year = new SimpleDateFormat("dd MMM H:mm");
public static final DateFormat sdf_date = new SimpleDateFormat("dd MMM yyyy");
public static final DateFormat sdf_date_no_year = new SimpleDateFormat("dd MMM");
public static final DateFormat sdf_time = new SimpleDateFormat("H:mm");
public static float scale = 0.0f;
public static class AnonymousClass18 {
static final int[] $SwitchMap$com$perm$kate$links$VkLinkType;
static {
int[] iArr = new int[VkLinkType.values().length];
$SwitchMap$com$perm$kate$links$VkLinkType = iArr;
try {
iArr[VkLinkType.PAGE.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.ARTICLE.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.PHOTO.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.ALBUM.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.PROFILE.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.GROUP.ordinal()] = 6;
} catch (NoSuchFieldError unused6) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.TOPIC.ordinal()] = 7;
} catch (NoSuchFieldError unused7) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.WALL_POST.ordinal()] = 8;
} catch (NoSuchFieldError unused8) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.DOMAIN.ordinal()] = 9;
} catch (NoSuchFieldError unused9) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.VKCC.ordinal()] = 10;
} catch (NoSuchFieldError unused10) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.EXTERNAL_LINK.ordinal()] = 11;
} catch (NoSuchFieldError unused11) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.DIALOG.ordinal()] = 12;
} catch (NoSuchFieldError unused12) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.ALBUMS.ordinal()] = 13;
} catch (NoSuchFieldError unused13) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.WALL.ordinal()] = 14;
} catch (NoSuchFieldError unused14) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.MAIL.ordinal()] = 15;
} catch (NoSuchFieldError unused15) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.VIDEO.ordinal()] = 16;
} catch (NoSuchFieldError unused16) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.MARKET_ITEM.ordinal()] = 17;
} catch (NoSuchFieldError unused17) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.MARKET_ALBUM.ordinal()] = 18;
} catch (NoSuchFieldError unused18) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.MARKET.ordinal()] = 19;
} catch (NoSuchFieldError unused19) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.WALL_COMMENT.ordinal()] = 20;
} catch (NoSuchFieldError unused20) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.TOPIC_COMMENT.ordinal()] = 21;
} catch (NoSuchFieldError unused21) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.AUDIO_PLAYLIST.ordinal()] = 22;
} catch (NoSuchFieldError unused22) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.POLL.ordinal()] = 23;
} catch (NoSuchFieldError unused23) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.CHAT_INVITE.ordinal()] = 24;
} catch (NoSuchFieldError unused24) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.STORY.ordinal()] = 25;
} catch (NoSuchFieldError unused25) {
}
try {
$SwitchMap$com$perm$kate$links$VkLinkType[VkLinkType.VIDEO_ALBUM.ordinal()] = 26;
} catch (NoSuchFieldError unused26) {
}
}
}
static {
NumberFormat numberFormat = NumberFormat.getInstance();
nf = numberFormat;
numberFormat.setMaximumFractionDigits(2);
}
public static void CopyStream(InputStream inputStream, OutputStream outputStream) {
CopyStream(inputStream, outputStream, null);
}
public static void CopyStream(InputStream inputStream, OutputStream outputStream, UploadProgressListener uploadProgressListener) {
byte[] bArr = new byte[1024];
int i = 0;
while (true) {
int read = inputStream.read(bArr, 0, 1024);
if (read == -1) {
return;
}
outputStream.write(bArr, 0, read);
i += read;
if (uploadProgressListener != null) {
uploadProgressListener.publishProgress(i);
}
}
}
public static void ShowAlbum(String str, long j, Context context) {
Intent intent = new Intent();
intent.setClass(context, PhotosActivity.class);
intent.putExtra("com.perm.kate.uid", str);
intent.putExtra("com.perm.kate.aid", j);
context.startActivity(intent);
}
public static void ShowComments(int i, Long l, long j, Context context) {
ShowComments(i, l, j, context, true);
}
public static void ShowComments(int i, Long l, long j, Context context, boolean z) {
ShowComments(i, l, j, false, context, z);
}
public static void ShowComments(int i, Long l, long j, boolean z, Context context) {
ShowComments(i, l, j, z, context, true);
}
public static void ShowComments(int i, Long l, long j, boolean z, Context context, boolean z2) {
Intent intent = new Intent();
intent.setClass(context, CommentsActivity.class);
intent.putExtra("com.perm.kate.current_photo_pid", l);
intent.putExtra("com.perm.kate.current_owner_id", j);
intent.putExtra("com.perm.kate.comment_type", i);
intent.putExtra("last_page", z);
intent.putExtra("can_post", z2);
context.startActivity(intent);
}
public static void ShowCreateComment(String str, String str2, Activity activity) {
if (str == null) {
return;
}
Intent intent = new Intent();
intent.setClass(activity, NewCommentActivity.class);
intent.putExtra("com.perm.kate.pid", str);
intent.putExtra("com.perm.kate.owner_id", str2);
intent.putExtra("com.perm.kate.comment_type", 1);
activity.startActivity(intent);
}
public static void ShowProfile(long j, Activity activity) {
ShowProfile(Long.toString(j), activity);
}
public static void ShowProfile(String str, Activity activity) {
Intent intent = new Intent();
intent.setClass(activity, ProfileInfoActivity.class);
intent.putExtra("com.perm.kate.user_id", str);
activity.startActivity(intent);
}
public static void checkCacheSizeSometimes(Context context) {
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
long currentTimeMillis = System.currentTimeMillis();
KApplication.getImageLoader().checkCacheSize();
long nanoTime = System.nanoTime();
KApplication.db.cleanAdEvents();
reportDbWriteDuration(nanoTime, "h_cleanAdEvents");
SharedPreferences.Editor edit = defaultSharedPreferences.edit();
edit.putLong("last_cache_check_1", currentTimeMillis);
edit.apply();
}
public static boolean checkLimitAttachments(BaseActivity baseActivity, int i, boolean z, boolean z2) {
int i2 = z ? 2 : 10;
if ((!z2 || i < i2) && (z2 || i <= i2)) {
return false;
}
baseActivity.displayToast(String.format(baseActivity.getString(R.string.toast_limit_attachments), Integer.valueOf(i2)));
return true;
}
public static void checkPhotoLink(String str, Activity activity, Fragment fragment) {
if (str != null) {
str = str.trim();
}
if (TextUtils.isEmpty(str)) {
return;
}
if (!str.startsWith("http://") && !str.startsWith("https://")) {
str = "http://" + str;
}
boolean isPhotoLink = isPhotoLink(str);
if (!isPhotoLink && InstagramHelper.isInstagramLink(str)) {
processInstagramLink(str, activity, fragment);
} else if (isPhotoLink) {
processPhotoLink(str, activity, fragment);
} else {
if (fragment != null) {
activity = fragment.getActivity();
}
Toast.makeText(activity, (int) R.string.open_link_failed, 0).show();
}
}
public static void checkTransparentTheme(Activity activity) {
if (BaseActivity.Theme != R.style.KateTransparent) {
return;
}
Drawable appBackground = getAppBackground(activity);
if (appBackground != null) {
activity.getWindow().setBackgroundDrawable(appBackground);
} else {
activity.getWindow().setFlags(1048576, 1048576);
}
}
public static void cleanup(Context context) {
try {
long j = PreferenceManager.getDefaultSharedPreferences(context).getLong("last_cache_check_1", 0L);
long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis - j > 72000000 || j - currentTimeMillis > 86400000) {
context.startService(new Intent(context, CleanupService.class));
}
} catch (Throwable th) {
th.printStackTrace();
reportError(th);
}
}
public static void closeStream(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void copyDocLink(long j, long j2, Context context) {
try {
copyText("https://vk.com/doc" + j + "_" + j2, context);
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void copyGroupLink(long j, String str, Context context) {
try {
StringBuilder sb = new StringBuilder();
sb.append("https://vk.com/");
if (TextUtils.isEmpty(str)) {
str = "club" + j;
}
sb.append(str);
copyText(sb.toString(), context);
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void copyGroupTopicLink(long j, long j2, Context context) {
try {
copyText("https://vk.com/topic-" + j2 + "_" + j, context);
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void copyPhotoAlbumLink(long j, long j2, Context context) {
String str;
int i = (int) j;
try {
if (i == -9000) {
str = "https://vk.com/tag" + j2;
} else if (i == -1000) {
str = "https://vk.com/photos" + j2;
} else if (i == -15) {
str = "https://vk.com/album" + j2 + "_000";
} else if (i == -7) {
str = "https://vk.com/album" + j2 + "_00";
} else if (i != -6) {
str = "https://vk.com/album" + j2 + "_" + j;
} else {
str = "https://vk.com/album" + j2 + "_0";
}
copyText(str, context);
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void copyPhotoLink(Photo photo, Context context, String str) {
if (photo == null) {
return;
}
try {
String str2 = "https://vk.com/photo" + photo.owner_id + "_" + photo.pid;
if (str != null && str.length() > 0) {
str2 = str2 + "?tag=" + str;
}
copyText(str2, context);
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void copyPostLink(String str, String str2, Context context) {
try {
copyText("https://vk.com/wall" + str + "_" + str2, context);
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void copyProfileLink(String str, Context context) {
try {
copyText("https://vk.com/id" + str, context);
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void copyText(String str, Context context) {
try {
((ClipboardManager) context.getSystemService("clipboard")).setText(str);
StringBuilder sb = new StringBuilder();
sb.append(context.getString(R.string.toast_copied_to_buffer));
sb.append(": ");
if (str != null && str.length() > 55) {
str = str.substring(0, 54) + "...";
}
sb.append(str);
Toast.makeText(context.getApplicationContext(), sb.toString(), 1).show();
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void copyVideoLink(long j, long j2, Context context) {
try {
copyText("https://vk.com/video" + j + "_" + j2, context);
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void createCopyContextMenu(final String str, final String str2, final String str3, final Context context) {
final ArrayList arrayList = new ArrayList();
if (isNotEmpty(str)) {
arrayList.add(new MenuItemDetails((int) R.string.copy_text, 7));
}
arrayList.add(new MenuItemDetails((int) R.string.label_copy_video_link, 8));
AlertDialog create = new AlertDialog.Builder(context).setItems(MenuItemDetails.toArray(arrayList), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
int i2 = ((MenuItemDetails) arrayList.get(i)).code;
if (i2 == 7) {
Helper.copyText(str, context);
} else if (i2 == 8) {
Helper.copyPostLink(str2, str3, context);
}
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
}).create();
create.setCanceledOnTouchOutside(true);
create.show();
}
public static void createCopyTextContextMenu(final String str, final Context context) {
try {
final ArrayList arrayList = new ArrayList();
arrayList.add(new MenuItemDetails((int) R.string.copy_text, 6));
AlertDialog create = new AlertDialog.Builder(context).setItems(MenuItemDetails.toArray(arrayList), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (((MenuItemDetails) arrayList.get(i)).code != 6) {
return;
}
Helper.copyText(str, context);
}
}).create();
create.setCanceledOnTouchOutside(true);
create.show();
} catch (Throwable th) {
th.printStackTrace();
reportError(th);
}
}
public static Intent createMainIntent(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(603979776);
return intent;
}
public static void displayLinksMenu(ArrayList arrayList, final Activity activity) {
ArrayList arrayList2 = new ArrayList(arrayList.size());
final ArrayList arrayList3 = new ArrayList(arrayList.size());
Iterator it = arrayList.iterator();
while (it.hasNext()) {
String str = (String) it.next();
Matcher matcher = NewsCursorAdapter.pattern.matcher(str);
if (matcher.find()) {
arrayList3.add("http://vk.com/" + matcher.group(1));
arrayList2.add(matcher.group(3));
} else if (Patterns.TEL.matcher(str).find()) {
arrayList3.add("tel:" + str);
arrayList2.add(str);
} else {
arrayList3.add(str);
arrayList2.add(str);
}
}
ArrayList arrayList4 = new ArrayList();
for (int i = 0; i < arrayList.size(); i++) {
arrayList4.add(new MenuItemDetails((CharSequence) arrayList2.get(i), 0));
}
AlertDialog create = new AlertDialog.Builder(activity).setTitle(R.string.links).setItems(MenuItemDetails.toArray(arrayList4), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
Helper.openUrl((String) arrayList3.get(i2), activity);
}
}).create();
create.setCanceledOnTouchOutside(true);
create.show();
}
public static boolean empty(String str) {
return str == null || str.length() == 0;
}
public static String[] extractLocationFromAttachments(ArrayList arrayList) {
if (arrayList != null) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
String str = (String) it.next();
if (str.contains("location:")) {
arrayList.remove(str);
return parseLocationString(str);
}
}
}
return new String[]{null, null};
}
public static ArrayList extractPattern(String str, Pattern pattern) {
ArrayList arrayList = new ArrayList();
if (str == null) {
return arrayList;
}
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
arrayList.add(matcher.group());
}
return arrayList;
}
public static ArrayList extractUrl(String str, boolean z) {
ArrayList extractPattern = extractPattern(str, Patterns.WEB_URL);
if (z) {
Matcher matcher = NewsCursorAdapter.pattern.matcher(str);
while (matcher.find()) {
extractPattern.add(matcher.group(0));
}
}
extractPattern.addAll(extractPattern(str, Patterns.TEL));
return extractPattern;
}
public static void fixNavBarColor(Activity activity, boolean z) {
if (Build.VERSION.SDK_INT < 21) {
return;
}
activity.getWindow().setNavigationBarColor(z ? -1 : -16777216);
}
public static boolean footerAddButtonEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("key_secret2", false);
}
public static int getAge(int i, int i2, int i3) {
GregorianCalendar gregorianCalendar = new GregorianCalendar();
int i4 = gregorianCalendar.get(1);
int i5 = gregorianCalendar.get(2);
int i6 = gregorianCalendar.get(5);
gregorianCalendar.set(i, i2, i3);
int i7 = i4 - gregorianCalendar.get(1);
if (i5 < gregorianCalendar.get(2) || (i5 == gregorianCalendar.get(2) && i6 < gregorianCalendar.get(5))) {
i7--;
}
if (i7 >= 0) {
return i7;
}
throw new IllegalArgumentException("Age < 0");
}
public static String getAgo(Context context, long j) {
return getAgo(context, j, true);
}
public static String getAgo(Context context, long j, boolean z) {
Date date = new Date(TimeFix.fix(j) * 1000);
if (DateUtils.isToday(1000 * j)) {
return sdf_time.format(date);
}
if (thisYear(j)) {
return (z ? sdf_date_time_no_year : sdf_date_no_year).format(date);
}
return (z ? sdf_date_time : sdf_date).format(date);
}
private static Drawable getAppBackground(Activity activity) {
String string;
Bitmap bitmap;
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
if (!defaultSharedPreferences.getBoolean("key_use_background", false) || (string = defaultSharedPreferences.getString("key_background", null)) == null || (bitmap = AppBackground.get(Uri.parse(string))) == null) {
return null;
}
return new ScaleBitmapDrawable(bitmap);
}
public static int getAvaStubId() {
return ImageLoader.roundAvatarsEnabled() ? R.drawable.no_photo_circle : getSquareStubId();
}
public static Activity getBaseActivity(Activity activity) {
while (activity.getParent() != null) {
activity = activity.getParent();
}
return activity;
}
public static int getDIP(double d) {
if (scale == 0.0f) {
scale = Resources.getSystem().getDisplayMetrics().density;
}
double d2 = scale;
Double.isNaN(d2);
return (int) Math.round(d2 * d);
}
public static String getDate(long j) {
return sdf_date_time.format(new Date(TimeFix.fix(j) * 1000));
}
public static Bitmap getDeletedAva() {
Bitmap decodeResource = BitmapFactory.decodeResource(KApplication.current.getResources(), R.drawable.ic_deleted_avatar);
return ImageLoader.roundAvatarsEnabled() ? ImageLoader.getRoundedBitmap(decodeResource) : decodeResource;
}
public static String getDeviceInfo() {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("app_version", getVersion().split(" ")[0]);
jSONObject.put("app_build", getVersionCode(KApplication.current));
jSONObject.put("system_name", "Android");
jSONObject.put("system_version", Build.VERSION.RELEASE);
jSONObject.put("manufacturer", Build.MANUFACTURER);
jSONObject.put("device_model", Build.MODEL);
jSONObject.put("ads_android_id", Settings.Secure.getString(KApplication.current.getContentResolver(), "android_id"));
AdvertisingIdClient.Info advertisingIdInfo = AdvertisingIdClient.getAdvertisingIdInfo(KApplication.current);
jSONObject.put("ads_device_id", advertisingIdInfo.getId());
jSONObject.put("ads_tracking_disabled", advertisingIdInfo.isLimitAdTrackingEnabled() ? 1 : 0);
} catch (Throwable th) {
th.printStackTrace();
reportError(th);
}
return jSONObject.toString();
}
public static String getDocumentDisplaySize(long j) {
if (j < 1024) {
return j + "B";
} else if (j < 1048576) {
return (j / 1024) + "KB";
} else {
StringBuilder sb = new StringBuilder();
NumberFormat numberFormat = nf;
double d = j;
Double.isNaN(d);
sb.append(numberFormat.format((d / 1024.0d) / 1024.0d));
sb.append("MB");
return sb.toString();
}
}
public static String getDurationTextBySeconds(long j) {
int i = ((int) j) / 60;
int i2 = (int) (j - (i * 60));
String str = i2 > 9 ? ":" : ":0";
return i + str + i2;
}
public static String getLastSee(Context context, long j, boolean z, boolean z2) {
String format;
Date date = new Date(TimeFix.fix(j) * 1000);
if (DateUtils.isToday(TimeFix.fix(j) * 1000)) {
format = ((Object) context.getText(R.string.label_today_at)) + " " + sdf_time.format(date);
} else if (DateUtils.isToday((86400 + j) * 1000)) {
format = ((Object) context.getText(R.string.yesteraday_at)) + " " + sdf_time.format(date);
} else {
format = thisYear(j) ? sdf_date_time_no_year.format(date) : sdf_date_time.format(date);
}
StringBuilder sb = new StringBuilder();
sb.append((Object) context.getText(z ? R.string.label_last_see_male : R.string.label_last_see_female));
sb.append(" ");
sb.append(format);
String sb2 = sb.toString();
if (z2) {
return sb2 + " " + ((Object) context.getText(R.string.from_mobile));
}
return sb2;
}
public static Bitmap getLinksAvatar() {
Bitmap decodeResource = BitmapFactory.decodeResource(KApplication.current.getResources(), R.drawable.links_icon);
return ImageLoader.roundAvatarsEnabled() ? ImageLoader.getRoundedBitmap(decodeResource) : decodeResource;
}
public static Class getLoginActivity() {
return Build.VERSION.SDK_INT >= 23 ? LoginActivity.class : LoginActivity2.class;
}
public static String getLongUrl(String str) {
Throwable th;
IOException e;
HttpURLConnection httpURLConnection;
try {
try {
httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
try {
httpURLConnection.setInstanceFollowRedirects(false);
httpURLConnection.setRequestMethod("GET");
int responseCode = httpURLConnection.getResponseCode();
if (responseCode == 301 || responseCode == 302) {
String headerField = httpURLConnection.getHeaderField("Location");
httpURLConnection.disconnect();
return headerField;
}
} catch (IOException e2) {
e = e2;
e.printStackTrace();
if (httpURLConnection == null) {
return "";
}
httpURLConnection.disconnect();
return "";
}
} catch (Throwable th2) {
th = th2;
if (str != 0) {
str.disconnect();
}
throw th;
}
} catch (IOException e3) {
e = e3;
httpURLConnection = null;
} catch (Throwable th3) {
th = th3;
str = 0;
if (str != 0) {
}
throw th;
}
httpURLConnection.disconnect();
return "";
}
public static void getMissingUsers(ArrayList arrayList) {
ArrayList arrayList2 = new ArrayList();
ArrayList arrayList3 = new ArrayList();
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Comment comment = (Comment) it.next();
long j = comment.from_id;
if (j > 0) {
arrayList2.add(Long.valueOf(j));
} else {
arrayList3.add(Long.valueOf(-j));
}
long j2 = comment.reply_to_uid;
if (j2 != 0) {
if (j2 > 0) {
arrayList2.add(Long.valueOf(j2));
} else {
arrayList3.add(Long.valueOf(-j2));
}
}
ArrayList<Comment> arrayList4 = comment.thread_comments;
if (arrayList4 != null && arrayList4.size() > 0) {
Iterator<Comment> it2 = comment.thread_comments.iterator();
while (it2.hasNext()) {
long j3 = it2.next().from_id;
if (j3 > 0) {
arrayList2.add(Long.valueOf(j3));
} else {
arrayList3.add(Long.valueOf(-j3));
}
}
}
}
KApplication.getMissingUsers(arrayList2);
KApplication.getMissingGroups(arrayList3);
}
private static void getPhotoById(final String str, final Context context) {
final Callback callback = new Callback((Activity) context) {
@Override
public void error(Throwable th) {
Helper.showProgressBar(false, context);
super.error(th);
}
@Override
public void ready(Object obj) {
Helper.showProgressBar(false, context);
ArrayList arrayList = (ArrayList) obj;
if (arrayList == null || arrayList.size() <= 0) {
return;
}
Helper.showActivity(2, null, 0L, arrayList, context);
}
};
showProgressBar(true, context);
new Thread() {
@Override
public void run() {
KApplication.session.getPhotosById(str, null, null, callback, (Activity) context);
}
}.start();
}
public static float getScale() {
if (scale == 0.0f) {
scale = Resources.getSystem().getDisplayMetrics().density;
}
return scale;
}
public static int getScreenSize(Context context) {
try {
return context.getResources().getConfiguration().screenLayout & 15;
} catch (Throwable th) {
th.printStackTrace();
reportError(th);
return 2;
}
}
public static Integer getSigHash() {
try {
Application application = KApplication.current;
Signature[] signatureArr = application.getPackageManager().getPackageInfo(application.getPackageName(), 64).signatures;
if (signatureArr == null || signatureArr.length <= 0) {
return null;
}
return Integer.valueOf(signatureArr[0].hashCode());
} catch (Throwable th) {
th.printStackTrace();
reportError(th);
return null;
}
}
public static int getSquareStubId() {
return R.drawable.d_no_photo4;
}
private static void getStory(String str, String str2, final Context context) {
final String str3 = str2 + "_" + str;
final Callback callback = new Callback((Activity) context) {
@Override
public void ready(Object obj) {
ArrayList arrayList = (ArrayList) obj;
if (arrayList == null || arrayList.size() <= 0) {
return;
}
StoriesActivity.getMissingUsers(arrayList);
StoriesActivity.openStory((Story) arrayList.get(0), arrayList, context);
}
};
showProgressBar(true, context);
new Thread() {
@Override
public void run() {
KApplication.session.getStoriesById(str3, callback, (Activity) context);
Helper.showProgressBar(false, context);
}
}.start();
}
public static String getStringAge(String str, Context context) {
try {
String[] split = str.split("\\.");
if (split.length == 3) {
int parseInt = Integer.parseInt(split[0]);
int age = getAge(Integer.parseInt(split[2]), Integer.parseInt(split[1]) - 1, parseInt);
int i = R.string.label_years0;
if (age != 11 && age != 12 && age != 13 && age != 14) {
int i2 = age % 10;
if (i2 == 1) {
i = R.string.label_years2;
} else if (i2 == 2 || i2 == 3 || i2 == 4) {
i = R.string.label_years1;
}
}
return " (" + age + " " + context.getString(i) + ")";
}
return "";
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
return "";
}
}
public static String getStringDate(long j, Context context) {
try {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(TimeFix.fix(j) * 1000);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d MMMM yyyy");
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("HH:mm");
return simpleDateFormat.format(calendar.getTime()) + " " + context.getString(R.string.label_at) + " " + simpleDateFormat2.format(calendar.getTime());
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
return "";
}
}
public static void getUserIdFromLink(String str, final Callback callback, final Context context) {
final VkLink parse = VkLinkParser.parse(str);
if (parse == null) {
return;
}
VkLinkType vkLinkType = parse.type;
if (vkLinkType == VkLinkType.PROFILE) {
if (callback != null) {
callback.ready(Long.valueOf(Long.parseLong(parse.id)));
}
} else if (vkLinkType == VkLinkType.GROUP) {
callback.ready(Long.valueOf(-Long.parseLong(parse.id)));
} else if (vkLinkType == VkLinkType.DOMAIN) {
User fetchUserByDomain = KApplication.db.fetchUserByDomain(parse.domain);
if (fetchUserByDomain != null && callback != null) {
callback.ready(Long.valueOf(fetchUserByDomain.uid));
return;
}
final Callback callback2 = new Callback((Activity) context) {
@Override
public void error(Throwable th) {
Helper.showProgressBar(false, context);
}
@Override
public void ready(Object obj) {
Helper.showProgressBar(false, context);
ArrayList arrayList = (ArrayList) obj;
if (arrayList == null || arrayList.size() <= 0) {
return;
}
KApplication.db.createOrUpdateUser((User) arrayList.get(0), false);
Callback callback3 = callback;
if (callback3 != null) {
callback3.ready(Long.valueOf(((User) arrayList.get(0)).uid));
}
}
};
showProgressBar(true, context);
new Thread() {
@Override
public void run() {
ArrayList arrayList = new ArrayList();
arrayList.add(VkLink.this.domain);
Api.tag = "gUIFL";
KApplication.session.getProfiles(null, arrayList, null, null, callback2, (Activity) context);
}
}.start();
}
}
public static String getVersion() {
return "109.1";
}
public static int getVersionCode(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getApplicationInfo().packageName, 0).versionCode;
} catch (PackageManager.NameNotFoundException unused) {
return 0;
}
}
public static void hideKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService("input_method");
View currentFocus = activity.getCurrentFocus();
if (currentFocus == null) {
currentFocus = new View(activity);
}
inputMethodManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
public static synchronized String installation_id() {
String string;
synchronized (Helper.class) {
SharedPreferences sharedPreferences = KApplication.current.getSharedPreferences("PREF_UNIQUE_ID", 0);
string = sharedPreferences.getString("PREF_UNIQUE_ID", null);
if (string == null) {
string = UUID.randomUUID().toString();
sharedPreferences.edit().putString("PREF_UNIQUE_ID", string).apply();
}
}
return string;
}
public static boolean isAdminOrEditorInGroup(long j) {
try {
Session session = KApplication.session;
if (session == null) {
return false;
}
return KApplication.db.isAdminOrEditorInGroup(Long.valueOf(Long.parseLong(session.getMid())), j);
} catch (Throwable th) {
th.printStackTrace();
reportError(th);
return false;
}
}
public static boolean isFinishActivitiesOptionEnabled(Context context) {
int i;
if (Build.VERSION.SDK_INT < 17) {
return false;
}
i = Settings.Global.getInt(context.getContentResolver(), "always_finish_activities", 0);
return i == 1;
}
public static boolean isGoogleMapsSupported() {
try {
int isGooglePlayServicesAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(KApplication.current);
Log.i("Kate.Helper", "resultCode=" + isGooglePlayServicesAvailable);
return isGooglePlayServicesAvailable == 0;
} catch (Throwable th) {
th.printStackTrace();
reportError(th);
return false;
}
}
public static boolean isLink(String str) {
ArrayList extractUrl;
if (TextUtils.isEmpty(str) || (extractUrl = extractUrl(str, false)) == null || extractUrl.size() != 1) {
return false;
}
String str2 = (String) extractUrl.get(0);
if (!str.equals(str2)) {
if (!str.equals(str2 + "/")) {
return false;
}
}
return true;
}
public static boolean isNoiseException(Throwable th) {
return (th instanceof SocketException) || (th instanceof SocketTimeoutException) || (th instanceof UnknownHostException) || (th instanceof WrongResponseCodeException) || (th instanceof IOException) || (th instanceof SSLException);
}
public static boolean isNotEmpty(String str) {
return str != null && str.length() > 0;
}
private static boolean isPhotoLink(String str) {
String lowerCase = str.toLowerCase();
return lowerCase.contains(".jpg") || lowerCase.contains(".jpeg") || lowerCase.contains(".png");
}
public static boolean isWifi() {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) KApplication.current.getSystemService("connectivity")).getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.getType() == 1;
}
public static void lambda$openVK_COMlink$0(VkLink vkLink, Context context) {
long nanoTime = System.nanoTime();
User fetchUserByDomain = KApplication.db.fetchUserByDomain(vkLink.domain);
reportDbReadDuration(nanoTime, "h_fetchUserByDomain", null);
if (fetchUserByDomain != null) {
showActivity(0, String.valueOf(fetchUserByDomain.uid), fetchUserByDomain.uid, null, context);
} else {
resolveScreenName(vkLink.domain, context);
}
}
public static String limitFilename(String str) {
if (str.length() > 125) {
str = str.substring(0, 125);
}
return str.replace('?', ' ').replace('\"', ' ').replace('*', ' ').replace('/', ' ').replace(':', ' ').replace('>', ' ').replace('<', ' ').replace('\\', ' ').replace('|', ' ');
}
public static Bitmap loadImageFromWeb(String str) {
try {
HttpURLConnection connection = ProxyManager.getConnection(new URL(str));
UserAgent.set(connection);
Bitmap decodeStream = BitmapFactory.decodeStream(connection.getInputStream());
connection.getInputStream().close();
connection.disconnect();
return decodeStream;
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
return null;
}
}
public static ArrayList makeUriList(Uri uri) {
ArrayList arrayList = new ArrayList();
arrayList.add(uri);
return arrayList;
}
public static ArrayList makeUriList(ArrayList arrayList) {
ArrayList arrayList2 = new ArrayList();
Iterator it = arrayList.iterator();
while (it.hasNext()) {
arrayList2.add((Uri) ((Parcelable) it.next()));
}
return arrayList2;
}
public static void onDial(Context context, String str) {
try {
context.startActivity(new Intent("android.intent.action.DIAL", Uri.parse("tel:" + str)));
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void onEmail(Context context, String str, String str2, String str3) {
try {
Intent intent = new Intent("android.intent.action.SEND");
intent.setType("text/plain");
intent.putExtra("android.intent.extra.EMAIL", new String[]{str});
intent.putExtra("android.intent.extra.SUBJECT", str2);
intent.putExtra("android.intent.extra.TEXT", str3);
context.startActivity(intent);
} catch (ActivityNotFoundException unused) {
Toast.makeText(context.getApplicationContext(), (int) R.string.no_email, 0).show();
} catch (Throwable th) {
reportError(th);
th.printStackTrace();
}
}
public static void openAudioPlaylist(long j, long j2, String str, Activity activity, boolean z) {
Intent intent = new Intent();
intent.setClass(activity, AudioActivity2.class);
intent.putExtra("playlist_id", j);
intent.putExtra("com.perm.kate.owner_id", j2);
intent.putExtra("access_key", str);
intent.putExtra("com.perm.kate.select_audio", z);
activity.startActivityForResult(intent, 11);
}
public static void openComment(VkLink vkLink, Context context) {
String str;
if (vkLink.type == VkLinkType.TOPIC_COMMENT) {
str = "https://m.vk.com/topic-" + vkLink.owner_id + "_" + vkLink.topic_id + "?post=" + vkLink.comment_id + "#post" + vkLink.comment_id;
} else {
str = "https://m.vk.com/wall" + vkLink.owner_id + "_" + vkLink.id + "?reply=" + vkLink.comment_id + "#reply" + vkLink.comment_id;
}
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra("com.perm.kate.title", context.getString(R.string.text_comment));
intent.putExtra("com.perm.kate.url", str);
context.startActivity(intent);
}
public static void openMap(String str, String str2, Activity activity) {
try {
if (isGoogleMapsSupported()) {
Intent intent = new Intent();
intent.setClass(activity, GoogleMapsActivity.class);
intent.putExtra("com.perm.kate.only_show", true);
intent.putExtra("com.perm.kate.latitude", str);
intent.putExtra("com.perm.kate.longitude", str2);
activity.startActivity(intent);
} else {
activity.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(String.format("geo:0,0?q=%s,%s", str, str2))));
}
} catch (ActivityNotFoundException e) {
e.printStackTrace();
reportError(e);
}
}
static void openMarket(long j, Context context) {
Intent intent = new Intent();
intent.setClass(context, MarketAlbumsActivity.class);
intent.putExtra("group_id", j);
context.startActivity(intent);
}
static void openMarketAlbum(long j, long j2, Context context) {
Intent intent = new Intent();
intent.setClass(context, MarketItemsActivity.class);
intent.putExtra("album_id", j);
intent.putExtra("group_id", j2);
context.startActivity(intent);
}
public static void openMarketItem(long j, long j2, Context context) {
Intent intent = new Intent();
intent.setClass(context, MarketItemActivity.class);
intent.putExtra("item_id", j);
intent.putExtra("owner_id", j2);
context.startActivity(intent);
}
public static void openPhoto(String str, Activity activity, String str2) {
openPhoto(str, activity, null, str2);
}
public static void openPhoto(String str, Activity activity, String str2, String str3) {
Intent intent = new Intent(activity, PhotoViewerActrivity.class);
Photo photo = new Photo();
photo.src = str3;
photo.src_big = str;
photo.phototext = str2;
ArrayList arrayList = new ArrayList();
arrayList.add(photo);
intent.putExtra("com.perm.kate.photos", arrayList);
activity.startActivity(intent);
}
private static void openPhotoAlbums(Context context, long j) {
Intent intent = new Intent();
intent.setClass(context, AlbumsActivity2.class);
intent.putExtra("com.perm.kate.owner_id", j);
context.startActivity(intent);
}
public static void openUrl(String str, Context context) {
if (openVK_COMlink(str, context)) {
return;
}
openUrlInBrowser(str, context);
}
public static void openUrlInBrowser(String str, Context context) {
openUrlInBrowser(str, context, false);
}
public static void openUrlInBrowser(String str, Context context, boolean z) {
try {
boolean startsWith = str.startsWith("tel:");
if (!str.startsWith("http://") && !str.startsWith("https://") && !startsWith) {
str = "http://" + str;
}
boolean contains = str.contains("://t.me/");
if (z || !useInternalWebBrowser(context) || contains || startsWith) {
context.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
return;
}
Intent intent = new Intent(context, WebActivity2.class);
intent.putExtra("url", str);
context.startActivity(intent);
} catch (Throwable th) {
th.printStackTrace();
reportError(th);
}
}
public static boolean openVK_COMlink(String str, final Context context) {
try {
final VkLink parse = VkLinkParser.parse(str);
if (parse == null) {
return false;
}
switch (AnonymousClass18.$SwitchMap$com$perm$kate$links$VkLinkType[parse.type.ordinal()]) {
case 1:
case 2:
showWebActivity(str, null, context);
return true;
case 3:
getPhotoById(parse.photo, context);
return true;
case 4:
ShowAlbum(parse.owner_id, Long.parseLong(parse.album_id), context);
return true;
case 5:
showActivity(0, parse.id, 0L, null, context);
return true;
case 6:
showActivity(1, null, Long.parseLong(parse.id), null, context);
return true;
case 7:
ShowComments(4, Long.valueOf(Long.parseLong(parse.topic_id)), Long.parseLong(parse.owner_id), context);
return true;
case 8:
showWallPost(Long.valueOf(Long.parseLong(parse.id)), Long.valueOf(Long.parseLong(parse.owner_id)), context);
return true;
case 9:
new Thread(new Runnable() {
@Override
public final void run() {
Helper.lambda$openVK_COMlink$0(VkLink.this, context);
}
}).start();
return true;
case 10:
openVkcc(str, context);
return true;
case 11:
openUrl(parse.link, context);
return true;
case 12:
showMessages(Long.valueOf(Long.parseLong(parse.id)), context);
return true;
case 13:
openPhotoAlbums(context, Long.parseLong(parse.id));
return true;
case 14:
ProfileFragment.ShowWallAcivity((Activity) context, Long.valueOf(Long.parseLong(parse.owner_id)));
return true;
case 15:
context.startActivity(new Intent(context, DialogsActivity.class));
return true;
case 16:
VideoLogic.fetchAndPlay(Long.parseLong(parse.id), Long.parseLong(parse.owner_id), null, (BaseActivity) context, false);
return true;
case 17:
openMarketItem(Long.parseLong(parse.id), Long.parseLong(parse.owner_id), context);
return true;
case 18:
openMarketAlbum(Long.parseLong(parse.album_id), Long.parseLong(parse.owner_id), context);
return true;
case 19:
openMarket(Long.parseLong(parse.owner_id), context);
return true;
case 20:
case 21:
openComment(parse, context);
return true;
case 22:
openAudioPlaylist(Long.parseLong(parse.id), Long.parseLong(parse.owner_id), parse.access_key, (Activity) context, false);
return true;
case 23:
Intent intent = new Intent();
intent.setClass(context, PollActivity.class);
intent.putExtra("com.perm.kate.poll_id", Long.parseLong(parse.id));
intent.putExtra("com.perm.kate.owner_id", Long.parseLong(parse.owner_id));
context.startActivity(intent);
return true;
case com.google.android.material.R$styleable.TabLayout_tabUnboundedRipple:
Intent intent2 = new Intent(context, ChatInviteActivity.class);
intent2.putExtra("link", str);
context.startActivity(intent2);
return true;
case 25:
getStory(parse.id, parse.owner_id, context);
return true;
case 26:
openVideoAlbum(Long.parseLong(parse.id), Long.parseLong(parse.owner_id), false, (Activity) context);
return true;
default:
return false;
}
} catch (Throwable th) {
th.printStackTrace();
reportError(th, str);
return false;
}
}
public static void openVideoAlbum(long j, long j2, boolean z, Activity activity) {
Intent intent = new Intent();
intent.setClass(activity, VideoActivity2.class);
intent.putExtra("album_id", j);
intent.putExtra("com.perm.kate.user_id", j2);
intent.putExtra("com.perm.kate.select_video", z);
activity.startActivityForResult(intent, 11);
}
private static void openVkcc(final String str, final Context context) {
new Thread() {
@Override
public void run() {
String longUrl = Helper.getLongUrl(str);
if (TextUtils.isEmpty(longUrl)) {
Helper.openUrlInBrowser(str, context);
} else {
Helper.openUrl(longUrl, context);
}
}
}.start();
}
public static String[] parseLocationString(String str) {
String[] split = str.replace("location:", "").split(";");
return split.length == 2 ? split : new String[]{null, null};
}
private static void processInstagramLink(String str, final Activity activity, final Fragment fragment) {
final FragmentActivity activity2 = fragment != null ? fragment.getActivity() : activity;
new InstagramHelper(new InstagramHelper.Callback() {
@Override
public void completed(String str2) {
Helper.processPhotoLink(str2, activity, fragment);
}
@Override
public void error() {
Activity activity3 = activity2;
if (activity3 instanceof BaseActivity) {
((BaseActivity) activity3).displayToast(R.string.error_photo_from_site);
}
}
}).getPhotoUrl(str);
}
public static void processPhotoLink(String str, final Activity activity, final Fragment fragment) {
final FragmentActivity activity2 = fragment != null ? fragment.getActivity() : activity;
PhotoSaver.PhotoSaverCallback photoSaverCallback = new PhotoSaver.PhotoSaverCallback() {
@Override
public void completed(Uri uri) {
Activity activity3 = activity2;
if (activity3 instanceof BaseActivity) {
((BaseActivity) activity3).showProgressBar(false);
}
ArrayList arrayList = new ArrayList();
arrayList.add(uri);
Intent intent = new Intent(activity2, PhotoUploadOptionsActivity.class);
intent.putExtra("uris", arrayList);
PhotoChooser.startActivity(activity, fragment, intent, 7);
}
@Override
public void error() {
Activity activity3 = activity2;
if (activity3 instanceof BaseActivity) {
((BaseActivity) activity3).showProgressBar(false);
((BaseActivity) activity2).displayToast(R.string.error_photo_from_site);
}
}
};
if (activity2 instanceof BaseActivity) {
BaseActivity baseActivity = (BaseActivity) activity2;
baseActivity.displayToast(R.string.downloading_photo_from_site);
baseActivity.showProgressBar(true);
}
PhotoSaver.saveTempPhoto(activity2, str, photoSaverCallback);
}
public static String removeBrokenChar(String str) {
int i;
return (str != null && (i = Build.VERSION.SDK_INT) >= 26 && i <= 28) ? str.replace("\u200f", "") : str;
}
public static void reportDbReadDuration(long j, String str, Cursor cursor) {
reportDbReadDuration(j, str, cursor, 1.0f);
}
public static void reportDbReadDuration(long j, String str, Cursor cursor, float f) {
if ((j / 10) % ((int) (1000000.0f / f)) >= 4) {
return;
}
if (cursor != null) {
cursor.getCount();
}
long nanoTime = System.nanoTime();
Exception exc = new Exception(str);
exc.setStackTrace(new StackTraceElement[]{new StackTraceElement("FakeClass", "dbReadDur", "FakeClass.java", 1)});
reportError(exc, Long.toString((nanoTime - j) / 1000000), true);
}
public static void reportDbWriteDuration(long j, String str) {
if (j % 100000 < 99999) {
return;
}
long nanoTime = System.nanoTime();
Exception exc = new Exception(str);
exc.setStackTrace(new StackTraceElement[]{new StackTraceElement("FakeClass", "dbWriteDur", "FakeClass.java", 1)});
reportError(exc, Long.toString((nanoTime - j) / 1000000), true);
}
public static void reportError(Throwable th) {
reportError(th, null);
}
public static void reportError(Throwable th, String str) {
reportError(th, str, false);
}
public static void reportError(Throwable th, String str, boolean z) {
}
public static void reportEvent(String str, Map map, int i) {
}
public static void reportItemClick(String str, String str2) {
if (System.nanoTime() % 100000 < 99999) {
return;
}
reportStats(str, "itemClick", str2);
}
public static void reportStats(String str, String str2, String str3) {
}
public static void reportTableSize() {
if (System.currentTimeMillis() % 10000 >= 5) {
return;
}
String str = new String[]{"users", "news", "photos", "albumphoto", "news_photo", "news_friend", "news_note", "friends", "messages", "comments", "albums", "notes", "cities", "countries", "audio", "audio_in_list", "wall", "attachments", "graffiti", "groups", "user_group", "video", "wall_like", "poll", "group_topics", "chat_members", "chat", "fave_users", "fave_links", "video_in_album", "fave_posts", "fave_groups", "docs", "audio_cache", "video_cache", "audio_albums", "ad_events"}[(int) (System.currentTimeMillis() % 37)];
reportStats(str, "tableSize", Long.toString(KApplication.db.getRowCount(str)));
}
public static void repostToGroup(String str, String str2, Activity activity, Fragment fragment) {
long parseLong = Long.parseLong(str2);
long parseLong2 = Long.parseLong(str);
Intent intent = new Intent();
intent.setClass(activity, GroupsActivity2.class);
intent.putExtra("com.perm.kate.select_group", true);
intent.putExtra("repost_post_id", parseLong);
intent.putExtra("repost_post_owner_id", parseLong2);
PhotoChooser.startActivity(activity, fragment, intent, 11);
}
private static void resolveScreenName(final String str, final Context context) {
final Callback callback = new Callback(context instanceof Activity ? (Activity) context : null) {
@Override
public void error(Throwable th) {
Helper.showProgressBar(false, context);
}
@Override
public void ready(Object obj) {
Helper.showProgressBar(false, context);
ScreenNameInfo screenNameInfo = (ScreenNameInfo) obj;
if ("user".equals(screenNameInfo.type)) {
Helper.showActivity(0, String.valueOf(screenNameInfo.object_id), 0L, null, context);
}
if ("group".equals(screenNameInfo.type)) {
Helper.showActivity(1, "", screenNameInfo.object_id, null, context);
}
}
};
showProgressBar(true, context);
new Thread() {
@Override
public void run() {
Context context2 = context;
KApplication.session.resolveScreenName(str, callback, context2 instanceof Activity ? (Activity) context2 : null);
}
}.start();
}
public static void sendToFriend(String str, String str2, Activity activity, boolean z) {
StringBuilder sb = new StringBuilder();
sb.append(z ? "wall_ads" : "wall");
sb.append(str);
sb.append("_");
sb.append(str2);
String sb2 = sb.toString();
Intent intent = new Intent();
intent.setClass(activity, MembersActivity.class);
intent.putExtra("com.perm.kate.only_members", false);
intent.putExtra("com.perm.kate.new_message", true);
intent.putExtra("com.perm.kate.photo_attachment", sb2);
activity.startActivity(intent);
}
public static void setFooterAddButtonEnabled(Context context, boolean z) {
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("key_secret2", z).apply();
}
public static void share(String str, Context context) {
Intent intent = new Intent();
intent.setAction("android.intent.action.SEND");
intent.setType("text/plain");
intent.putExtra("android.intent.extra.TEXT", str);
context.startActivity(Intent.createChooser(intent, null));
}
public static void sharePhoto(String str, String str2, Context context) {
share("https://vk.com/photo" + str + "_" + str2, context);
}
public static void sharePost(String str, String str2, Context context) {
share("https://vk.com/wall" + str + "_" + str2, context);
}
private static boolean shouldDrop() {
String lowerCase = getVersion().toLowerCase();
return (lowerCase.contains("beta") || lowerCase.contains("test") || System.nanoTime() % 100 < 1) ? false : true;
}
public static void showActivity(int i, String str, long j, ArrayList arrayList, Context context) {
Intent intent = new Intent();
if (i == 0) {
intent.setClass(context, ProfileInfoActivity.class);
intent.putExtra("com.perm.kate.user_id", str);
} else if (i == 1) {
intent.setClass(context, GroupActivity.class);
intent.putExtra("com.perm.kate.group_id", j);
} else if (i != 2) {
return;
} else {
intent.setClass(context, PhotoViewerActrivity.class);
intent.putExtra("com.perm.kate.photos", arrayList);
}
context.startActivity(intent);
}
public static void showAllPhotos(Activity activity, String str) {
Intent intent = new Intent();
intent.setClass(activity, PhotosActivity.class);
intent.putExtra("com.perm.kate.aid", -1000L);
intent.putExtra("com.perm.kate.uid", str);
activity.startActivity(intent);
}
public static void showCreatePhotoComment(String str, String str2, Activity activity) {
if (str == null) {
return;
}
Intent intent = new Intent();
intent.setClass(activity, NewCommentActivity.class);
intent.putExtra("com.perm.kate.pid", str);
intent.putExtra("com.perm.kate.owner_id", str2);
intent.putExtra("com.perm.kate.comment_type", 0);
activity.startActivity(intent);
}
public static void showCreateVideoComment(String str, String str2, Activity activity) {
if (str == null) {
return;
}
Intent intent = new Intent();
intent.setClass(activity, NewCommentActivity.class);
intent.putExtra("com.perm.kate.pid", str);
intent.putExtra("com.perm.kate.owner_id", str2);
intent.putExtra("com.perm.kate.comment_type", 2);
activity.startActivity(intent);
}
public static void showGroup(long j, Activity activity) {
Intent intent = new Intent();
intent.setClass(activity, GroupActivity.class);
intent.putExtra("com.perm.kate.group_id", j);
activity.startActivity(intent);
}
public static void showGroupBlockActivity(long j, long j2, Activity activity) {
if (j < 0) {
j *= -1;
}
Intent intent = new Intent();
intent.setClass(activity, GroupBanActivity.class);
intent.putExtra("com.perm.kate.group_id", j);
intent.putExtra("com.perm.kate.user_id", j2);
activity.startActivity(intent);
}
public static void showMessages(Long l, Context context) {
Intent intent = new Intent();
intent.setClass(context, MessageThreadActivity.class);
intent.putExtra("com.perm.kate.message_uid", l);
context.startActivity(intent);
}
public static void showPhotoLinkDialog(final Activity activity, final Fragment fragment) {
View inflate = LayoutInflater.from(fragment != null ? fragment.getActivity() : activity).inflate(R.layout.add_friend, (ViewGroup) null);
final EditText editText = (EditText) inflate.findViewById(R.id.et_message);
editText.setHint("http://");
AlertDialog.Builder builder = new AlertDialog.Builder(fragment != null ? fragment.getActivity() : activity);
builder.setTitle(R.string.link_to_photo).setView(inflate).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Helper.checkPhotoLink(editText.getText().toString(), activity, fragment);
}
}).setNegativeButton(R.string.label_cancel, (DialogInterface.OnClickListener) null);
builder.create().show();
}
public static void showProgressBar(boolean z, Context context) {
if (context instanceof BaseActivity) {
((BaseActivity) context).showProgressBar(z);
}
}
public static void showPublishStatusDialog(final Activity activity, final long j, final String str, final boolean z) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(R.string.text_publish_new_status).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
new Thread() {
@Override
public void run() {
Session session = KApplication.session;
AnonymousClass9 anonymousClass9 = AnonymousClass9.this;
session.createWallPost(j, str, null, null, false, z, false, null, null, null, 0L, null, null, activity);
}
}.start();
}
}).setNegativeButton(R.string.no, (DialogInterface.OnClickListener) null);
AlertDialog create = builder.create();
create.setCanceledOnTouchOutside(true);
create.show();
}
public static void showShareDialog(final BaseActivity baseActivity, final String str, final String str2, boolean z, boolean z2, final RepostHelper.RepostCallback repostCallback, final Fragment fragment, final boolean z3) {
final ArrayList arrayList = new ArrayList();
if (z) {
arrayList.add(new MenuItemDetails((int) R.string.publish_desc, 1010));
}
arrayList.add(new MenuItemDetails((int) R.string.label_menu_send_to_friend, 1014));
if (z2) {
arrayList.add(new MenuItemDetails((int) R.string.publish_to_group, 1012));
}
arrayList.add(new MenuItemDetails((int) R.string.label_send_to, 1016));
AlertDialog create = new AlertDialog.Builder(baseActivity).setItems(MenuItemDetails.toArray(arrayList), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
int i2 = ((MenuItemDetails) arrayList.get(i)).code;
if (i2 == 1010) {
new RepostHelper(baseActivity, repostCallback).createRepostDialog(Long.parseLong(str), Long.parseLong(str2), null, z3);
} else if (i2 == 1012) {
Helper.repostToGroup(str2, str, baseActivity, fragment);
} else if (i2 == 1014) {
Helper.sendToFriend(str2, str, baseActivity, z3);
} else if (i2 == 1016) {
Helper.sharePost(str2, str, baseActivity);
}
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
}).create();
create.setCanceledOnTouchOutside(true);
create.show();
}
public static void showTextDialogForCopy(String str, Activity activity) {
TextView textView = (TextView) LayoutInflater.from(activity).inflate(R.layout.text_item, (ViewGroup) null);
textView.setText(SmileHelper.getSmiledText(activity, new SpannableStringBuilder(str)));
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setView(textView).setPositiveButton(R.string.close, (DialogInterface.OnClickListener) null);
AlertDialog create = builder.create();
create.setCanceledOnTouchOutside(true);
create.show();
((BaseActivity) activity).displayToast(R.string.toast_select_text);
}
public static void showWallPost(Long l, Long l2, Context context) {
showWallPost(l, l2, false, false, context);
}
public static void showWallPost(Long l, Long l2, boolean z, boolean z2, Context context) {
Intent intent = new Intent();
intent.setClass(context, WallMessageActivity.class);
intent.putExtra("post_id", l);
intent.putExtra("owner_id", l2);
intent.putExtra("dont_refresh", z2);
intent.putExtra("is_suggested", z);
context.startActivity(intent);
}
public static void showWebActivity(String str, String str2, Context context) {
Intent intent = new Intent();
intent.setClass(context, WebActivity.class);
intent.putExtra("com.perm.kate.url", str);
if (isNotEmpty(str2)) {
intent.putExtra("com.perm.kate.title", str2);
}
context.startActivity(intent);
}
static boolean thisYear(long j) {
if (year_start_long == 0) {
year_start_long = new GregorianCalendar(new GregorianCalendar().get(1), 0, 1).getTimeInMillis();
}
return j * 1000 > year_start_long;
}
public static boolean useInternalWebBrowser(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("key_internal_browser", false);
}
}