Kate Mobile v109.1版本的 MD5 值为:fcd76ded5f363ecbfac46035a4ed2a23
以下内容为反编译后的 DataHelper.java 源代码,内容仅作参考
package com.perm.kate.db;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import com.perm.kate.ForwardedMessagesActivity;
import com.perm.kate.Helper;
import com.perm.kate.KApplication;
import com.perm.kate.ThreadIdHelper;
import com.perm.kate.WallMessageActivity;
import com.perm.kate.api.Album;
import com.perm.kate.api.Attachment;
import com.perm.kate.api.Audio;
import com.perm.kate.api.AudioAlbum;
import com.perm.kate.api.ChatMember;
import com.perm.kate.api.Comment;
import com.perm.kate.api.Document;
import com.perm.kate.api.Geo;
import com.perm.kate.api.Gift;
import com.perm.kate.api.Group;
import com.perm.kate.api.GroupTopic;
import com.perm.kate.api.Link;
import com.perm.kate.api.Message;
import com.perm.kate.api.NewsItem;
import com.perm.kate.api.Newsfeed;
import com.perm.kate.api.Note;
import com.perm.kate.api.Page;
import com.perm.kate.api.Photo;
import com.perm.kate.api.Privacy;
import com.perm.kate.api.Sticker;
import com.perm.kate.api.User;
import com.perm.kate.api.Video;
import com.perm.kate.api.VkPoll;
import com.perm.kate.api.WallMessage;
import com.perm.utils.TranslitTransformer;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
public class DataHelper {
private final Context mCtx;
private OpenHelper mDbHelper;
public static class OpenHelper extends SQLiteOpenHelper {
OpenHelper(Context context) {
super(context, "kate.db", (SQLiteDatabase.CursorFactory) null, 181);
}
private void createAdEventsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table ad_events(type integer,ads_id1 integer,ads_id2 integer,date integer)");
sQLiteDatabase.execSQL("create index AdEventsIndex1 on ad_events(type,ads_id1,ads_id2);");
sQLiteDatabase.execSQL("create index AdEventsIndex2 on ad_events(date);");
}
private void createAlbumPhotoTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table albumphoto(_id integer primary key, album_id integer, album_owner_id integer, photo_id integer, photo_owner_id integer );");
sQLiteDatabase.execSQL("create index index_albumphoto_1 on albumphoto(album_owner_id, album_id);");
}
private void createAttachmentsIndex1(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_attachments_1 on attachments(content_type, content_id);");
}
private void createAttachmentsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table attachments(_id integer primary key, content_type integer, content_id integer, type text, photo_id integer, posted_photo_id integer, audio_id integer, video_id integer, video_owner_id integer, video_access_key text, poll_id integer, poll_owner_id integer, note_id integer, link_url text, link_title text, link_desc text, link_img text, graffiti_id integer, graffiti_owner_id integer, graffiti_src text, graffiti_src_big text, geo_type text, geo_lat text, geo_lon text, doc_id integer, page_title text, page_id integer, page_group_id integer, message blob );");
}
private void createAudioAlbumsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table audio_albums(_id integer primary key, album_id integer, owner_id integer, photo text, title text );");
}
private void createAudioCacheTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table audio_cache(_id integer primary key, audio_id integer, owner_id integer, status integer, position integer );");
sQLiteDatabase.execSQL("create index index_audio_cache on audio_cache(audio_id);");
}
private void createAudioInListTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table audio_in_list(_id integer primary key,list_id integer,list_owner_id integer,audio_id integer)");
createAudioInListIndex(sQLiteDatabase);
}
private void createAudioIndex1(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_audio_1 on audio(audio_id);");
}
private void createAudioTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table audio(_id integer primary key, audio_id integer, owner_id integer, artist text, title text, duration integer, url text, genre_id integer, lyrics_id integer );");
}
private void createChatMembersTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table chat_members(_id integer primary key, chat_id integer, user_id integer );");
sQLiteDatabase.execSQL("create index index_chat_members on chat_members(chat_id);");
}
private void createChatTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table chat(_id integer primary key, chat_id integer, account_id integer, group_id integer not null default 0, title text, photo_100 text, unread_count integer );");
}
private void createCommentsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table comments(_id integer primary key, comment_id integer, date integer, from_id integer, message text, content_type integer, content_owner_id integer, content_id integer, reply_to_cid integer, reply_to_uid integer, like_count integer );");
createCommentsIndex(sQLiteDatabase);
}
private void createDocsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table docs(_id integer primary key, doc_id integer, owner_id integer, title text, size integer, url text, ext text, thumb text, thumb_s text, title_lower text )");
sQLiteDatabase.execSQL("create index index_doc_owner on docs(owner_id)");
}
private void createFaveGroupsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table fave_groups(_id integer primary key, account_id integer, group_id integer );");
}
private void createFaveLinksTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table fave_links(_id integer primary key, account_id integer, url text, title text, description text, image_src text, link_id text );");
}
private void createFavePostsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table fave_posts(_id integer primary key, account_id integer, post_id integer, owner_id integer );");
}
private void createFaveUsersTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table fave_users(_id integer primary key, account_id integer, user_id integer );");
}
private void createGraffitiTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table graffiti(_id integer primary key, owner_id integer, src text, src_big text );");
}
private void createGroupTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table groups(_id integer primary key, name text, name_lower text, photo text, photo_medium text, photo_big text, is_closed integer, description text, wiki text, can_see_all_posts integer default 1, fixed_post integer, members_count integer, type integer, start_date integer, status text, photos integer, albums integer, topics integer, videos integer, audios integer, docs integer, posts integer, podcasts integer, can_message integer, market_enabled integer, market_contact_id integer, market_wiki_id integer, market_wiki_title text, cover_400 text, cover_800 text, verified integer );");
}
private void createGroupTopicsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table group_topics(_id integer primary key, group_id integer, title text, created integer, created_by text, updated integer, updated_by text, is_closed integer, is_fixed integer, title_lower text, comments integer );");
sQLiteDatabase.execSQL("create index index_group_topic_group_id on group_topics(group_id);");
}
private void createMessagesIndex1(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_messages_1 on messages(account_id, group_id, message_id);");
}
private void createMessagesTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table messages(_id integer primary key, message_id integer, account_id integer, group_id integer not null default 0, date integer, uid integer, title text, body text, read_state integer, chat_id integer, is_out integer, have_attachments integer, important integer, update_time integer, [action] integer, action_mid integer, attachments blob, action_text text );");
}
private void createNewsTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table news(_id integer primary key, account_id integer, type text, source_id integer, from_id integer, date integer, post_id integer, copy_owner_id integer, copy_post_id integer, copy_text text, text text, signer_id integer, like_count integer, user_like integer, comment_count integer, comment_can_post integer, is_comments integer not null default 0, comments text, reposts_count integer, views integer, ads_title text, ads_id1 integer, ads_id2 integer, ad_data text, ad_data_impression text, age_restriction text, statistics blob, track_code text, advertiser_info_url text, attachments blob, user_reposted integer, copyright_link text, copyright_name text );");
}
private void createPhotoIndex1(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_photo_1 on photos(photo_id);");
}
private void createPhotosTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table photos(_id integer primary key, photo_id integer, owner_id integer, album_id integer, src text, phototext text, created integer, src_big text, src_xbig text, src_xxbig text, src_xxxbig text, src_small text, like_count integer, width integer, height integer, lat text, lon text, comments_count integer);");
}
private void createPollTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table poll(_id integer primary key, account_id integer, poll_id integer, owner_id integer, answers text, created integer, question text, votes integer, anonymous integer );");
}
private void createUserGroupTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table user_group(_id integer primary key, user_id integer, group_id integer, admin_level integer );");
createIndexUserGroup(sQLiteDatabase);
}
private void createUsersTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table users(_id integer primary key, is_full integer not null, first_name text not null, last_name text not null, nickname text, photo text, photo_medium text, photo_medium_rec text, photo_big text, photo_200 text, photo_400_orig text, domain text, sex integer, birthdate text, city integer, country integer, rate integer, mobile_phone text, home_phone text, university integer, university_name text, faculty integer, faculty_name text, first_name_lower text, last_name_lower text, nickname_lower text, online integer, online_mobile integer, graduation integer, status text, relation integer, last_seen integer, albums integer, photos integer, videos integer, audios integer, notes integer, friends integer, user_photos integer, user_videos integer, groups integer, followers integer, online_friends integer, mutual_friends integer, gifts integer, posts integer, crop_photo_rect_x1 real, crop_photo_rect_x2 real, crop_photo_rect_y1 real, crop_photo_rect_y2 real, cover_400 text, cover_960 text, verified integer );");
}
private void createVideoCacheTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table video_cache(_id integer primary key, video_id integer, owner_id integer, access_key text, status integer );");
sQLiteDatabase.execSQL("create index index_video_cache on video_cache(video_id,owner_id);");
}
private void createVideoInAlbumTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table video_in_album(_id integer primary key, album_id integer, album_owner_id integer, video_id integer, video_owner_id integer );");
sQLiteDatabase.execSQL("create index index_video_in_album on video_in_album(album_id,album_owner_id);");
}
private void createVideoIndex1(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_video_1 on video(video_id, owner_id);");
}
private void createVideoTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table video(_id integer primary key, video_id integer, owner_id integer, title text, description text, duration integer, link text, image text, image_big text, date integer, player_url text, video_url text, views integer, likes_count integer, platform text);");
}
private void createWallIndex1(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_wall_1 on wall(to_id)");
}
private void createWallIndex2(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_wall_2 on wall(to_id,post_id)");
}
static void createWallLikeIndex(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_wall_like on wall_like (type, wall_owner_id, post_id)");
}
private void createWallLikeTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table wall_like(_id integer primary key, wall_owner_id integer not null, post_id integer not null, account_id integer not null, [like] integer not null, reposted integer, type integer not null );");
createWallLikeIndex(sQLiteDatabase);
}
private void createWallTable(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create table wall(_id integer primary key, post_id integer, to_id integer, from_id integer, date integer, text text, comments_count integer, likes_count integer, signer_id integer, copy_owner_id integer, copy_post_id integer, copy_text text, reposts_count integer, post_type integer, views integer, is_pinned integer, copyright_link text, attachments blob, copyright_name text, created_by integer );");
createWallIndex1(sQLiteDatabase);
createWallIndex2(sQLiteDatabase);
}
private void recreateAll(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS users");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS news");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS friends");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS photos");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS news_photo");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS news_phototags");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS news_friend");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS news_note");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS messages");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS comments");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS albums");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS notes");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS cities");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS countries");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS audio");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS wall");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS graffiti");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS groups");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS user_group");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS video");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS wall_like");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS attachments");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS poll");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS chat");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS group_topics");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS chat_members");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS fave_users");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS fave_links");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS fave_posts");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS docs");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS albumphoto");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS audio_cache");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS video_in_album");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS video_cache");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS audio_albums");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS audio_in_list");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS ad_events");
sQLiteDatabase.execSQL("DROP TABLE IF EXISTS fave_groups");
onCreate(sQLiteDatabase);
}
private void update(SQLiteDatabase sQLiteDatabase, int i) {
if (i == 126) {
sQLiteDatabase.execSQL("ALTER TABLE chat ADD unread_count integer");
}
if (i == 127) {
createVideoCacheTable(sQLiteDatabase);
}
if (i == 128) {
sQLiteDatabase.execSQL("ALTER TABLE users ADD posts integer");
}
if (i == 129) {
sQLiteDatabase.execSQL("ALTER TABLE groups ADD posts integer");
}
if (i == 130) {
sQLiteDatabase.execSQL("ALTER TABLE users ADD photo_400_orig text");
}
if (i == 131) {
createAudioAlbumsTable(sQLiteDatabase);
}
if (i == 132) {
sQLiteDatabase.execSQL("ALTER TABLE users ADD verified integer");
}
if (i == 133) {
sQLiteDatabase.execSQL("ALTER TABLE groups ADD verified integer");
}
if (i == 134) {
createAudioInListTable(sQLiteDatabase);
}
if (i == 135) {
sQLiteDatabase.execSQL("ALTER TABLE users ADD mutual_friends integer");
}
if (i == 136) {
sQLiteDatabase.execSQL("ALTER TABLE groups ADD can_message integer");
}
if (i == 137) {
sQLiteDatabase.execSQL("ALTER TABLE groups ADD market_enabled integer");
sQLiteDatabase.execSQL("ALTER TABLE groups ADD market_contact_id integer");
sQLiteDatabase.execSQL("ALTER TABLE groups ADD market_wiki_id integer");
sQLiteDatabase.execSQL("ALTER TABLE groups ADD market_wiki_title text");
}
if (i == 138) {
sQLiteDatabase.execSQL("ALTER TABLE users ADD photos integer");
}
if (i == 139) {
sQLiteDatabase.execSQL("ALTER TABLE albums ADD privacy_str text");
}
if (i == 140) {
sQLiteDatabase.execSQL("ALTER TABLE messages ADD group_id integer not null default 0");
sQLiteDatabase.execSQL("ALTER TABLE chat ADD group_id integer not null default 0");
sQLiteDatabase.execSQL("DROP INDEX IF EXISTS index_messages_1");
createMessagesIndex1(sQLiteDatabase);
}
if (i == 141) {
sQLiteDatabase.execSQL("ALTER TABLE photos RENAME TO photos_old");
createPhotosTable(sQLiteDatabase);
}
if (i == 142) {
createPhotoIndex1(sQLiteDatabase);
}
if (i == 143) {
sQLiteDatabase.execSQL("ALTER TABLE docs ADD doc_id integer");
}
if (i == 144) {
sQLiteDatabase.execSQL("ALTER TABLE users ADD crop_photo_rect_x1 real");
sQLiteDatabase.execSQL("ALTER TABLE users ADD crop_photo_rect_x2 real");
sQLiteDatabase.execSQL("ALTER TABLE users ADD crop_photo_rect_y1 real");
sQLiteDatabase.execSQL("ALTER TABLE users ADD crop_photo_rect_y2 real");
}
if (i == 145) {
sQLiteDatabase.execSQL("ALTER TABLE news_photo ADD photo_owner_id integer");
sQLiteDatabase.execSQL("ALTER TABLE news_phototags ADD photo_owner_id integer");
}
if (i == 146) {
sQLiteDatabase.execSQL("ALTER TABLE albumphoto ADD photo_owner_id integer");
}
if (i == 147) {
sQLiteDatabase.execSQL("ALTER TABLE groups ADD cover_400 text");
sQLiteDatabase.execSQL("ALTER TABLE groups ADD cover_800 text");
}
if (i == 148) {
sQLiteDatabase.execSQL("ALTER TABLE wall ADD views integer");
sQLiteDatabase.execSQL("ALTER TABLE news ADD views integer");
}
if (i == 149) {
sQLiteDatabase.execSQL("ALTER TABLE comments ADD reply_to_cid integer");
sQLiteDatabase.execSQL("ALTER TABLE comments ADD reply_to_uid integer");
}
if (i == 150) {
sQLiteDatabase.execSQL("ALTER TABLE wall_like ADD reposted integer");
}
if (i == 151) {
sQLiteDatabase.execSQL("ALTER TABLE audio ADD genre_id integer");
}
if (i == 152) {
sQLiteDatabase.execSQL("ALTER TABLE group_topics ADD title_lower text");
}
if (i == 153) {
sQLiteDatabase.execSQL("ALTER TABLE messages ADD update_time integer");
}
if (i == 154) {
sQLiteDatabase.execSQL("ALTER TABLE news ADD ads_title text");
sQLiteDatabase.execSQL("ALTER TABLE news ADD ads_id1 integer");
sQLiteDatabase.execSQL("ALTER TABLE news ADD ads_id2 integer");
sQLiteDatabase.execSQL("ALTER TABLE news ADD ad_data text");
sQLiteDatabase.execSQL("ALTER TABLE news ADD ad_data_impression text");
sQLiteDatabase.execSQL("ALTER TABLE news ADD age_restriction text");
sQLiteDatabase.execSQL("ALTER TABLE news ADD statistics blob");
sQLiteDatabase.execSQL("ALTER TABLE news ADD track_code text");
}
if (i == 155) {
createAdEventsTable(sQLiteDatabase);
}
if (i == 156) {
sQLiteDatabase.execSQL("ALTER TABLE news ADD attachments blob");
}
if (i == 157) {
sQLiteDatabase.execSQL("ALTER TABLE photos ADD lat text");
sQLiteDatabase.execSQL("ALTER TABLE photos ADD lon text");
}
if (i == 158) {
createFaveGroupsTable(sQLiteDatabase);
}
if (i == 159) {
sQLiteDatabase.execSQL("ALTER TABLE groups ADD podcasts integer");
}
if (i == 160) {
sQLiteDatabase.execSQL("ALTER TABLE albums ADD privacy_comments text");
}
if (i == 161) {
sQLiteDatabase.execSQL("ALTER TABLE news ADD copyright_link text");
sQLiteDatabase.execSQL("ALTER TABLE news ADD copyright_name text");
sQLiteDatabase.execSQL("ALTER TABLE wall ADD copyright_link text");
sQLiteDatabase.execSQL("ALTER TABLE wall ADD copyright_name text");
}
if (i == 162) {
sQLiteDatabase.execSQL("ALTER TABLE video ADD platform text");
}
if (i == 163) {
createWallIndex1(sQLiteDatabase);
}
if (i == 164) {
sQLiteDatabase.execSQL("ALTER TABLE wall ADD attachments blob");
}
if (i == 165) {
sQLiteDatabase.execSQL("ALTER TABLE audio_albums ADD photo text");
}
if (i == 166) {
sQLiteDatabase.execSQL("ALTER TABLE messages ADD attachments blob");
}
if (i == 167) {
sQLiteDatabase.execSQL("ALTER TABLE wall ADD created_by integer");
}
if (i == 168) {
createCommentsIndex(sQLiteDatabase);
}
if (i == 169) {
createFriendsIndex(sQLiteDatabase);
}
if (i == 170) {
createAudioInListIndex(sQLiteDatabase);
}
if (i == 171) {
createWallLikeIndex(sQLiteDatabase);
}
if (i == 174) {
createIndexNewsPhoto(sQLiteDatabase);
createIndexMessages2(sQLiteDatabase);
}
if (i == 175) {
createIndexNewsPhotoTag(sQLiteDatabase);
createIndexNewsFriend(sQLiteDatabase);
}
if (i == 176) {
createIndexUserGroup(sQLiteDatabase);
}
if (i == 177) {
createWallIndex2(sQLiteDatabase);
}
if (i == 178) {
sQLiteDatabase.execSQL("ALTER TABLE video_cache ADD access_key text");
}
if (i == 179) {
sQLiteDatabase.execSQL("ALTER TABLE users ADD cover_400 text");
sQLiteDatabase.execSQL("ALTER TABLE users ADD cover_960 text");
}
if (i == 180) {
sQLiteDatabase.execSQL("ALTER TABLE news ADD advertiser_info_url text");
}
}
void createAudioInListIndex(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_audio_in_list on audio_in_list(list_owner_id)");
}
public void createCommentsIndex(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index INDEX_COMMENTS on comments(content_id)");
}
void createFriendsIndex(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index index_friends on friends(owner_id)");
}
public void createIndexMessages2(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index IF NOT EXISTS index_messages_2 on messages(chat_id,account_id,group_id,message_id)");
}
public void createIndexNewsFriend(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index IF NOT EXISTS index_news_friend on news_friend(news_id)");
}
public void createIndexNewsPhoto(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index IF NOT EXISTS index_news_photo on news_photo(news_id)");
}
public void createIndexNewsPhotoTag(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index IF NOT EXISTS index_news_phototag on news_phototags(news_id)");
}
public void createIndexUserGroup(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("create index IF NOT EXISTS index_user_group on user_group(user_id)");
}
@Override
public void onConfigure(SQLiteDatabase sQLiteDatabase) {
DataHelper.setPragmaSync(sQLiteDatabase);
super.onConfigure(sQLiteDatabase);
}
@Override
public void onCreate(SQLiteDatabase sQLiteDatabase) {
createUsersTable(sQLiteDatabase);
createNewsTable(sQLiteDatabase);
sQLiteDatabase.execSQL("create table friends(_id integer primary key, owner_id integer, friend_id integer);");
createFriendsIndex(sQLiteDatabase);
createPhotosTable(sQLiteDatabase);
createPhotoIndex1(sQLiteDatabase);
sQLiteDatabase.execSQL("create table news_photo(_id integer primary key, news_id integer, photo_id integer,photo_owner_id integer);");
createIndexNewsPhoto(sQLiteDatabase);
sQLiteDatabase.execSQL("create table news_phototags(_id integer primary key, news_id integer, photo_id integer,photo_owner_id integer);");
createIndexNewsPhotoTag(sQLiteDatabase);
sQLiteDatabase.execSQL("create table news_friend(_id integer primary key, news_id integer, user_id integer);");
createIndexNewsFriend(sQLiteDatabase);
sQLiteDatabase.execSQL("create table news_note(_id integer primary key, news_id integer, note_id integer);");
createMessagesTable(sQLiteDatabase);
createCommentsTable(sQLiteDatabase);
sQLiteDatabase.execSQL("create table albums(_id integer primary key, album_id integer, thumb_id integer, owner_id integer, title text, description text, created integer, updated integer, size integer, privacy_str text, privacy_comments text, thumb_src text);");
sQLiteDatabase.execSQL("create table notes(_id integer primary key, comments integer, comments_read integer, title text, text text, date integer, from_id integer );");
sQLiteDatabase.execSQL("create table cities(_id integer primary key, name text );");
sQLiteDatabase.execSQL("create table countries(_id integer primary key, name text );");
createAudioTable(sQLiteDatabase);
createWallTable(sQLiteDatabase);
createGraffitiTable(sQLiteDatabase);
createGroupTable(sQLiteDatabase);
createUserGroupTable(sQLiteDatabase);
createVideoTable(sQLiteDatabase);
createWallLikeTable(sQLiteDatabase);
createChatMembersTable(sQLiteDatabase);
createChatTable(sQLiteDatabase);
createAttachmentsTable(sQLiteDatabase);
createPollTable(sQLiteDatabase);
createGroupTopicsTable(sQLiteDatabase);
createAttachmentsIndex1(sQLiteDatabase);
createAudioIndex1(sQLiteDatabase);
createVideoIndex1(sQLiteDatabase);
createMessagesIndex1(sQLiteDatabase);
createIndexMessages2(sQLiteDatabase);
createFaveUsersTable(sQLiteDatabase);
createFaveLinksTable(sQLiteDatabase);
createFavePostsTable(sQLiteDatabase);
createDocsTable(sQLiteDatabase);
createAlbumPhotoTable(sQLiteDatabase);
createAudioCacheTable(sQLiteDatabase);
createVideoInAlbumTable(sQLiteDatabase);
createVideoCacheTable(sQLiteDatabase);
createAudioAlbumsTable(sQLiteDatabase);
createAudioInListTable(sQLiteDatabase);
createAdEventsTable(sQLiteDatabase);
createFaveGroupsTable(sQLiteDatabase);
}
@Override
public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
Log.w("Kate.DataHelper", "Upgrading database from version " + i + " to " + i2);
if (i < 126) {
recreateAll(sQLiteDatabase);
return;
}
while (i < i2) {
try {
update(sQLiteDatabase, i);
i++;
} catch (SQLiteException e) {
recreateAll(sQLiteDatabase);
Helper.reportError(e);
e.printStackTrace();
return;
}
}
}
void setWriteAheadLoggingEnabledWithReflection(boolean z) {
setWriteAheadLoggingEnabled(z);
}
}
public DataHelper(Context context) {
this.mCtx = context;
}
private ArrayList audioCursorToArray(Cursor cursor) {
int columnIndex = cursor.getColumnIndex("audio_id");
int columnIndex2 = cursor.getColumnIndex("artist");
int columnIndex3 = cursor.getColumnIndex("duration");
int columnIndex4 = cursor.getColumnIndex("owner_id");
int columnIndex5 = cursor.getColumnIndex("title");
int columnIndex6 = cursor.getColumnIndex("url");
int columnIndex7 = cursor.getColumnIndex("lyrics_id");
int columnIndex8 = cursor.getColumnIndex("genre_id");
ArrayList arrayList = new ArrayList();
while (cursor.moveToNext()) {
Audio audio = new Audio();
audio.aid = cursor.getLong(columnIndex);
audio.artist = cursor.getString(columnIndex2);
audio.duration = cursor.getLong(columnIndex3);
audio.owner_id = cursor.getLong(columnIndex4);
audio.title = cursor.getString(columnIndex5);
audio.url = cursor.getString(columnIndex6);
audio.lyrics_id = Long.valueOf(cursor.getLong(columnIndex7));
if (!cursor.isNull(columnIndex8)) {
audio.track_genre_id = cursor.getInt(columnIndex8);
}
arrayList.add(audio);
}
return arrayList;
}
private int contentTypeToLikeType(long j) {
int i = (int) j;
if (i != 0) {
if (i != 1) {
if (i != 2) {
if (i != 4) {
return i != 5 ? -1 : 7;
}
return 5;
}
return 4;
}
return 2;
}
return 3;
}
private void createAttachedObjects(ArrayList arrayList, long j) {
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Attachment attachment = (Attachment) it.next();
Photo photo = attachment.photo;
if (photo != null) {
createOrUpdatePhoto(photo, j);
}
Note note = attachment.note;
if (note != null) {
createOrUpdateNote(note);
}
Video video = attachment.video;
if (video != null) {
createOrUpdateVideo(video);
}
if (attachment.poll != null) {
long nanoTime = System.nanoTime();
createOrUpdatePoll(attachment.poll, j);
Helper.reportDbWriteDuration(nanoTime, "dh_createOrUpdatePoll");
}
}
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
private void createFriendsInternal(long j, ArrayList arrayList) {
SQLiteStatement compileStatement = this.mDbHelper.getWritableDatabase().compileStatement("INSERT INTO friends(owner_id, friend_id) VALUES(?,?)");
Iterator it = arrayList.iterator();
while (it.hasNext()) {
compileStatement.bindLong(1, j);
compileStatement.bindLong(2, ((User) it.next()).uid);
compileStatement.execute();
}
compileStatement.close();
}
private void createNewsInternal(Newsfeed newsfeed, long j, int i) {
ArrayList arrayList = newsfeed.profiles;
if (arrayList != null) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateUser((User) it.next(), false);
}
}
ArrayList arrayList2 = newsfeed.groups;
if (arrayList2 != null) {
Iterator it2 = arrayList2.iterator();
while (it2.hasNext()) {
createOrUpdateGroup((Group) it2.next(), false);
}
}
Iterator it3 = newsfeed.items.iterator();
while (it3.hasNext()) {
NewsItem newsItem = (NewsItem) it3.next();
repostCompatibilityHack(newsItem);
createAttachedObjects(newsItem.attachments, j);
createNewsItem(newsItem, j, i);
}
}
private void createOrUpdateGroupTopic(GroupTopic groupTopic) {
if (updateGroupTopic(groupTopic)) {
return;
}
createGroupTopic(groupTopic);
}
private ArrayList cursorToVideoArray(Cursor cursor) {
ArrayList arrayList = new ArrayList();
int columnIndex = cursor.getColumnIndex("views");
int columnIndex2 = cursor.getColumnIndex("image_big");
int columnIndex3 = cursor.getColumnIndex("likes_count");
int columnIndex4 = cursor.getColumnIndex("like");
int columnIndex5 = cursor.getColumnIndex("platform");
while (cursor.moveToNext()) {
Video video = new Video();
video.title = cursor.getString(cursor.getColumnIndex("title"));
video.description = cursor.getString(cursor.getColumnIndex("description"));
video.duration = cursor.getLong(cursor.getColumnIndex("duration"));
video.owner_id = cursor.getLong(cursor.getColumnIndex("owner_id"));
video.player = cursor.getString(cursor.getColumnIndex("player_url"));
video.vid = cursor.getLong(cursor.getColumnIndex("video_id"));
video.image = cursor.getString(cursor.getColumnIndex("image"));
if (columnIndex != -1) {
video.views = cursor.getInt(columnIndex);
}
video.image_big = cursor.getString(columnIndex2);
if (columnIndex3 != -1) {
video.like_count = Integer.valueOf(cursor.getInt(columnIndex3));
}
if (columnIndex4 != -1) {
video.user_likes = Boolean.valueOf(cursor.getLong(columnIndex4) == 1);
}
if (columnIndex5 != -1) {
video.platform = cursor.getString(columnIndex5);
}
arrayList.add(video);
}
return arrayList;
}
public static ArrayList deserializeAttachments(byte[] bArr, long j) {
ArrayList arrayList = new ArrayList();
if (bArr == null) {
return arrayList;
}
try {
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bArr));
byte readByte = dataInputStream.readByte();
byte readByte2 = dataInputStream.readByte();
for (int i = 0; i < readByte2; i++) {
Attachment attachment = new Attachment();
String readUTF = dataInputStream.readUTF();
attachment.type = readUTF;
if (!readUTF.equals("photo") && !attachment.type.equals("posted_photo")) {
if (attachment.type.equals("link")) {
Link link = new Link();
attachment.link = link;
link.description = dataInputStream.readUTF();
attachment.link.image_src = dataInputStream.readUTF();
attachment.link.title = dataInputStream.readUTF();
attachment.link.url = dataInputStream.readUTF();
if (dataInputStream.readBoolean()) {
attachment.link.photo = new Photo();
attachment.link.photo.pid = dataInputStream.readLong();
attachment.link.photo.owner_id = Long.toString(dataInputStream.readLong());
attachment.link.photo.src = dataInputStream.readUTF();
attachment.link.photo.src_big = dataInputStream.readUTF();
attachment.link.photo.width = dataInputStream.readInt();
attachment.link.photo.height = dataInputStream.readInt();
}
arrayList.add(attachment);
} else if (attachment.type.equals("doc")) {
Document document = new Document();
attachment.document = document;
document.id = dataInputStream.readLong();
attachment.document.owner_id = dataInputStream.readLong();
attachment.document.access_key = dataInputStream.readUTF();
attachment.document.size = dataInputStream.readLong();
attachment.document.title = dataInputStream.readUTF();
attachment.document.url = dataInputStream.readUTF();
attachment.document.thumb = dataInputStream.readUTF();
attachment.document.ext = dataInputStream.readUTF();
attachment.document.thumb_o = dataInputStream.readUTF();
arrayList.add(attachment);
} else if (attachment.type.equals("audio")) {
Audio audio = new Audio();
attachment.audio = audio;
audio.aid = dataInputStream.readLong();
attachment.audio.owner_id = dataInputStream.readLong();
attachment.audio.artist = dataInputStream.readUTF();
attachment.audio.title = dataInputStream.readUTF();
attachment.audio.url = dataInputStream.readUTF();
attachment.audio.duration = dataInputStream.readLong();
attachment.audio.lyrics_id = Long.valueOf(dataInputStream.readLong());
if (attachment.audio.lyrics_id.longValue() == -1) {
attachment.audio.lyrics_id = null;
}
if (readByte > 4) {
attachment.audio.transcript = dataInputStream.readUTF();
}
if (readByte > 5) {
attachment.audio.access_key = dataInputStream.readUTF();
}
arrayList.add(attachment);
} else if (attachment.type.equals("video")) {
Video video = new Video();
attachment.video = video;
video.vid = dataInputStream.readLong();
attachment.video.owner_id = dataInputStream.readLong();
attachment.video.access_key = dataInputStream.readUTF();
attachment.video.title = dataInputStream.readUTF();
attachment.video.duration = dataInputStream.readLong();
attachment.video.player = dataInputStream.readUTF();
attachment.video.image = dataInputStream.readUTF();
attachment.video.image_big = dataInputStream.readUTF();
if (readByte >= 4) {
attachment.video.platform = dataInputStream.readUTF();
}
arrayList.add(attachment);
} else if (attachment.type.equals("note")) {
Note fetchNote = KApplication.db.fetchNote(dataInputStream.readLong());
attachment.note = fetchNote;
if (fetchNote != null) {
arrayList.add(attachment);
}
} else if (attachment.type.equals("poll")) {
VkPoll fetchPoll = KApplication.db.fetchPoll(dataInputStream.readLong(), j);
attachment.poll = fetchPoll;
if (fetchPoll != null) {
arrayList.add(attachment);
}
} else if (attachment.type.equals("geo")) {
Geo geo = new Geo();
attachment.geo = geo;
geo.type = dataInputStream.readUTF();
attachment.geo.lat = dataInputStream.readUTF();
attachment.geo.lon = dataInputStream.readUTF();
arrayList.add(attachment);
} else if (attachment.type.equals("page")) {
Page page = new Page();
attachment.page = page;
page.title = dataInputStream.readUTF();
attachment.page.id = dataInputStream.readLong();
attachment.page.group_id = dataInputStream.readLong();
arrayList.add(attachment);
} else if (attachment.type.equals("album")) {
Album album = new Album();
attachment.album = album;
album.aid = dataInputStream.readLong();
attachment.album.owner_id = dataInputStream.readLong();
attachment.album.title = dataInputStream.readUTF();
arrayList.add(attachment);
} else if (attachment.type.equals("wall_reply")) {
Comment comment = new Comment();
attachment.comment = comment;
comment.cid = dataInputStream.readLong();
attachment.comment.post = new WallMessage();
attachment.comment.post.id = dataInputStream.readLong();
attachment.comment.post.to_id = dataInputStream.readLong();
attachment.comment.message = dataInputStream.readUTF();
arrayList.add(attachment);
} else if (attachment.type.equals("sticker")) {
if (readByte >= 5) {
Sticker sticker = new Sticker();
attachment.sticker = sticker;
sticker.id = dataInputStream.readLong();
attachment.sticker.photo_64 = dataInputStream.readUTF();
attachment.sticker.photo_128 = dataInputStream.readUTF();
attachment.sticker.photo_256 = dataInputStream.readUTF();
attachment.sticker.animation_url = dataInputStream.readUTF();
arrayList.add(attachment);
}
} else if (attachment.type.equals("gift")) {
if (readByte >= 5) {
Gift gift = new Gift();
attachment.gift = gift;
gift.id = dataInputStream.readLong();
attachment.gift.thumb_256 = dataInputStream.readUTF();
arrayList.add(attachment);
}
} else if (attachment.type.equals("message")) {
if (readByte >= 5) {
Message deserialize = ForwardedMessagesActivity.deserialize(dataInputStream);
if (deserialize != null) {
deserialize.read_state = true;
attachment.message = deserialize;
}
arrayList.add(attachment);
}
} else if (attachment.type.equals("wall")) {
if (readByte >= 5) {
attachment.wallMessage = WallMessageActivity.deserialize(dataInputStream);
arrayList.add(attachment);
}
} else if (attachment.type.equals("friend")) {
User fetchUser = KApplication.db.fetchUser(dataInputStream.readLong());
attachment.user = fetchUser;
if (fetchUser != null) {
arrayList.add(attachment);
}
}
}
Photo photo = new Photo();
attachment.photo = photo;
photo.pid = dataInputStream.readLong();
attachment.photo.owner_id = Long.toString(dataInputStream.readLong());
attachment.photo.access_key = dataInputStream.readUTF();
attachment.photo.src = dataInputStream.readUTF();
attachment.photo.src_big = dataInputStream.readUTF();
attachment.photo.width = dataInputStream.readInt();
attachment.photo.height = dataInputStream.readInt();
arrayList.add(attachment);
}
dataInputStream.close();
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
return arrayList;
}
public static List deserializeStats(byte[] bArr) {
if (bArr == null) {
return null;
}
try {
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bArr));
dataInputStream.readByte();
byte readByte = dataInputStream.readByte();
ArrayList arrayList = new ArrayList();
for (int i = 0; i < readByte; i++) {
arrayList.add(new String[]{dataInputStream.readUTF(), dataInputStream.readUTF()});
}
dataInputStream.close();
return arrayList;
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
return null;
}
}
private int getSerializationLimit() {
int i = Build.VERSION.SDK_INT;
if (i <= 19) {
return 7;
}
if (i <= 20) {
return 11;
}
return i <= 25 ? 17 : 27;
}
private void limitAttachmentsDepth(Message message, int i) {
if (message != null) {
try {
ArrayList<Attachment> arrayList = message.attachments;
if (arrayList == null) {
return;
}
Iterator<Attachment> it = arrayList.iterator();
while (it.hasNext()) {
Attachment next = it.next();
if ("message".equals(next.type)) {
if (i > 0) {
limitAttachmentsDepth(next.message, i - 1);
} else {
Message message2 = new Message();
next.message = message2;
message2.body = "[Превышена глубина вложенности]";
Helper.reportStats("", "attDepth", null);
}
}
}
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
}
public static void repostCompatibilityHack(NewsItem newsItem) {
ArrayList arrayList = newsItem.copy_history;
if (arrayList != null) {
if (arrayList.size() > 1) {
StringBuilder sb = new StringBuilder();
WallMessage wallMessage = (WallMessage) newsItem.copy_history.get(0);
sb.append(wallMessage.text);
sb.append("\n\nhttp://vk.com/wall");
sb.append(((WallMessage) newsItem.copy_history.get(1)).to_id);
sb.append("_");
sb.append(((WallMessage) newsItem.copy_history.get(1)).id);
wallMessage.text = sb.toString();
}
if (newsItem.copy_history.size() > 0) {
newsItem.copy_text = newsItem.text;
newsItem.text = ((WallMessage) newsItem.copy_history.get(0)).text;
ArrayList arrayList2 = newsItem.attachments;
newsItem.attachments = ((WallMessage) newsItem.copy_history.get(0)).attachments;
if (arrayList2 != null && arrayList2.size() != 0) {
if (newsItem.attachments == null) {
newsItem.attachments = new ArrayList();
}
newsItem.attachments.addAll(arrayList2);
}
newsItem.copy_owner_id = ((WallMessage) newsItem.copy_history.get(0)).to_id;
newsItem.copy_post_id = ((WallMessage) newsItem.copy_history.get(0)).id;
}
newsItem.copy_history = null;
}
}
public static void repostCompatibilityHack(WallMessage wallMessage) {
ArrayList<WallMessage> arrayList;
if (wallMessage == null || (arrayList = wallMessage.copy_history) == null) {
return;
}
if (arrayList.size() > 1) {
StringBuilder sb = new StringBuilder();
WallMessage wallMessage2 = wallMessage.copy_history.get(0);
sb.append(wallMessage2.text);
sb.append("\n\nhttp://vk.com/wall");
sb.append(wallMessage.copy_history.get(1).to_id);
sb.append("_");
sb.append(wallMessage.copy_history.get(1).id);
wallMessage2.text = sb.toString();
}
if (wallMessage.copy_history.size() > 0) {
wallMessage.copy_text = wallMessage.text;
wallMessage.text = wallMessage.copy_history.get(0).text;
ArrayList<Attachment> arrayList2 = wallMessage.attachments;
wallMessage.attachments = wallMessage.copy_history.get(0).attachments;
if (arrayList2 != null && arrayList2.size() != 0) {
if (wallMessage.attachments == null) {
wallMessage.attachments = new ArrayList<>();
}
wallMessage.attachments.addAll(arrayList2);
}
wallMessage.copy_owner_id = wallMessage.copy_history.get(0).from_id;
}
wallMessage.copy_history = null;
}
private byte[] serializeAttachments(List list) {
if (list == null || list.size() == 0) {
return null;
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
dataOutputStream.writeByte(6);
dataOutputStream.writeByte(list.size());
Iterator it = list.iterator();
while (it.hasNext()) {
Attachment attachment = (Attachment) it.next();
dataOutputStream.writeUTF(attachment.type);
if (attachment.type.equals("photo")) {
dataOutputStream.writeLong(attachment.photo.pid);
dataOutputStream.writeLong(Long.parseLong(attachment.photo.owner_id));
String str = attachment.photo.access_key;
if (str == null) {
str = "";
}
dataOutputStream.writeUTF(str);
String str2 = attachment.photo.src;
if (str2 == null) {
str2 = "";
}
dataOutputStream.writeUTF(str2);
String str3 = attachment.photo.src_big;
dataOutputStream.writeUTF(str3 != null ? str3 : "");
dataOutputStream.writeInt(attachment.photo.width);
dataOutputStream.writeInt(attachment.photo.height);
} else if (attachment.type.equals("link")) {
String str4 = attachment.link.description;
if (str4 == null) {
str4 = "";
}
dataOutputStream.writeUTF(str4);
String str5 = attachment.link.image_src;
if (str5 == null) {
str5 = "";
}
dataOutputStream.writeUTF(str5);
String str6 = attachment.link.title;
if (str6 == null) {
str6 = "";
}
dataOutputStream.writeUTF(str6);
dataOutputStream.writeUTF(attachment.link.url);
dataOutputStream.writeBoolean(attachment.link.photo != null);
Photo photo = attachment.link.photo;
if (photo != null) {
dataOutputStream.writeLong(photo.pid);
dataOutputStream.writeLong(Long.parseLong(attachment.link.photo.owner_id));
String str7 = attachment.link.photo.src;
if (str7 == null) {
str7 = "";
}
dataOutputStream.writeUTF(str7);
String str8 = attachment.link.photo.src_big;
dataOutputStream.writeUTF(str8 != null ? str8 : "");
dataOutputStream.writeInt(attachment.link.photo.width);
dataOutputStream.writeInt(attachment.link.photo.height);
}
} else if (attachment.type.equals("doc")) {
dataOutputStream.writeLong(attachment.document.id);
dataOutputStream.writeLong(attachment.document.owner_id);
String str9 = attachment.document.access_key;
if (str9 == null) {
str9 = "";
}
dataOutputStream.writeUTF(str9);
dataOutputStream.writeLong(attachment.document.size);
dataOutputStream.writeUTF(attachment.document.title);
dataOutputStream.writeUTF(attachment.document.url);
String str10 = attachment.document.thumb;
if (str10 == null) {
str10 = "";
}
dataOutputStream.writeUTF(str10);
String str11 = attachment.document.ext;
if (str11 == null) {
str11 = "";
}
dataOutputStream.writeUTF(str11);
String str12 = attachment.document.thumb_o;
dataOutputStream.writeUTF(str12 != null ? str12 : "");
} else if (attachment.type.equals("audio")) {
dataOutputStream.writeLong(attachment.audio.aid);
dataOutputStream.writeLong(attachment.audio.owner_id);
dataOutputStream.writeUTF(attachment.audio.artist);
dataOutputStream.writeUTF(attachment.audio.title);
dataOutputStream.writeUTF(attachment.audio.url);
dataOutputStream.writeLong(attachment.audio.duration);
Long l = attachment.audio.lyrics_id;
dataOutputStream.writeLong(l != null ? l.longValue() : -1L);
String str13 = attachment.audio.transcript;
if (str13 == null) {
str13 = "";
}
dataOutputStream.writeUTF(str13);
String str14 = attachment.audio.access_key;
dataOutputStream.writeUTF(str14 != null ? str14 : "");
} else if (attachment.type.equals("video")) {
dataOutputStream.writeLong(attachment.video.vid);
dataOutputStream.writeLong(attachment.video.owner_id);
String str15 = attachment.video.access_key;
if (str15 == null) {
str15 = "";
}
dataOutputStream.writeUTF(str15);
dataOutputStream.writeUTF(attachment.video.title);
dataOutputStream.writeLong(attachment.video.duration);
String str16 = attachment.video.player;
if (str16 == null) {
str16 = "";
}
dataOutputStream.writeUTF(str16);
String str17 = attachment.video.image;
if (str17 == null) {
str17 = "";
}
dataOutputStream.writeUTF(str17);
String str18 = attachment.video.image_big;
if (str18 == null) {
str18 = "";
}
dataOutputStream.writeUTF(str18);
String str19 = attachment.video.platform;
dataOutputStream.writeUTF(str19 != null ? str19 : "");
} else if (attachment.type.equals("note")) {
dataOutputStream.writeLong(attachment.note.nid);
} else if (attachment.type.equals("poll")) {
dataOutputStream.writeLong(attachment.poll.id);
} else if (attachment.type.equals("geo")) {
String str20 = attachment.geo.type;
dataOutputStream.writeUTF(str20 != null ? str20 : "");
dataOutputStream.writeUTF(attachment.geo.lat);
dataOutputStream.writeUTF(attachment.geo.lon);
} else if (attachment.type.equals("page")) {
dataOutputStream.writeUTF(attachment.page.title);
dataOutputStream.writeLong(attachment.page.id);
dataOutputStream.writeLong(attachment.page.group_id);
} else if (attachment.type.equals("album")) {
dataOutputStream.writeLong(attachment.album.aid);
dataOutputStream.writeLong(attachment.album.owner_id);
dataOutputStream.writeUTF(attachment.album.title);
} else if (attachment.type.equals("wall_reply")) {
dataOutputStream.writeLong(attachment.comment.cid);
dataOutputStream.writeLong(attachment.comment.post.id);
dataOutputStream.writeLong(attachment.comment.post.to_id);
dataOutputStream.writeUTF(attachment.comment.message);
} else if (attachment.type.equals("sticker")) {
dataOutputStream.writeLong(attachment.sticker.id);
String str21 = attachment.sticker.photo_64;
if (str21 == null) {
str21 = "";
}
dataOutputStream.writeUTF(str21);
String str22 = attachment.sticker.photo_128;
if (str22 == null) {
str22 = "";
}
dataOutputStream.writeUTF(str22);
String str23 = attachment.sticker.photo_256;
if (str23 == null) {
str23 = "";
}
dataOutputStream.writeUTF(str23);
String str24 = attachment.sticker.animation_url;
dataOutputStream.writeUTF(str24 != null ? str24 : "");
} else if (attachment.type.equals("gift")) {
dataOutputStream.writeLong(attachment.gift.id);
dataOutputStream.writeUTF(attachment.gift.thumb_256);
} else if (attachment.type.equals("message")) {
limitAttachmentsDepth(attachment.message, getSerializationLimit());
dataOutputStream.write(serialize(attachment.message));
} else if (attachment.type.equals("wall")) {
repostCompatibilityHack(attachment.wallMessage);
dataOutputStream.write(serialize(attachment.wallMessage));
} else if (attachment.type.equals("friend")) {
dataOutputStream.writeLong(attachment.user.uid);
}
}
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
return byteArrayOutputStream.toByteArray();
}
private byte[] serializeStats(List list) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
dataOutputStream.writeByte(1);
dataOutputStream.writeByte(list.size());
Iterator it = list.iterator();
while (it.hasNext()) {
String[] strArr = (String[]) it.next();
dataOutputStream.writeUTF(strArr[0]);
dataOutputStream.writeUTF(strArr[1]);
}
return byteArrayOutputStream.toByteArray();
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
return null;
}
}
static void setPragmaSync(SQLiteDatabase sQLiteDatabase) {
try {
sQLiteDatabase.execSQL("PRAGMA synchronous=OFF");
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
private String[] toArg(long j) {
return new String[]{Long.toString(j)};
}
public void DeleteAndCreateVideos(long j, long j2, ArrayList arrayList, long j3) {
long currentTimeMillis = System.currentTimeMillis();
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
deleteVideosInAlbum(j, j2);
createOrUpdateVideos(arrayList);
createOrUpdateVideoUserLikes(arrayList, j3);
createVideosInAlbum(j, j2, arrayList);
writableDatabase.setTransactionSuccessful();
writableDatabase.endTransaction();
long currentTimeMillis2 = System.currentTimeMillis();
Log.i("Kate.DataHelper", "DeleteAndCreateVideos duration " + (currentTimeMillis2 - currentTimeMillis) + " ms");
} catch (Throwable th) {
writableDatabase.endTransaction();
throw th;
}
}
public boolean adEventExists(int i, int i2, int i3) {
Cursor query = this.mDbHelper.getWritableDatabase().query("ad_events", new String[]{"type"}, "type=? AND ads_id1=? AND ads_id2=?", new String[]{Long.toString(i), Long.toString(i2), Long.toString(i3)}, null, null, null, "1");
boolean z = query.getCount() != 0;
query.close();
return z;
}
public void addVideoToCache(long j, long j2, String str) {
addVideoToCache(j, j2, str, 0);
}
public void addVideoToCache(long j, long j2, String str, int i) {
ContentValues contentValues = new ContentValues();
contentValues.put("video_id", Long.valueOf(j));
contentValues.put("owner_id", Long.valueOf(j2));
contentValues.put("access_key", str);
contentValues.put("status", Integer.valueOf(i));
this.mDbHelper.getWritableDatabase().insertOrThrow("video_cache", null, contentValues);
}
public void addVideosToCache(ArrayList arrayList) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Long[] lArr = (Long[]) it.next();
KApplication.db.addVideoToCache(lArr[1].longValue(), lArr[0].longValue(), null, 2);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void cleanAdEvents() {
this.mDbHelper.getWritableDatabase().delete("ad_events", "date<= ?", toArg(millisToEventTime(System.currentTimeMillis() - 86400000)));
}
public void cleanTable(String str) {
try {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.execSQL("delete from " + str + " where _id in (select _id from " + str + " limit 2000)");
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
public void clearCache() {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
writableDatabase.execSQL("DELETE FROM users");
writableDatabase.execSQL("DELETE FROM news");
writableDatabase.execSQL("DELETE FROM friends");
writableDatabase.execSQL("DELETE FROM photos");
writableDatabase.execSQL("DELETE FROM news_photo");
writableDatabase.execSQL("DELETE FROM news_phototags");
writableDatabase.execSQL("DELETE FROM news_friend");
writableDatabase.execSQL("DELETE FROM news_note");
writableDatabase.execSQL("DELETE FROM messages");
writableDatabase.execSQL("DELETE FROM comments");
writableDatabase.execSQL("DELETE FROM albums");
writableDatabase.execSQL("DELETE FROM notes");
writableDatabase.execSQL("DELETE FROM cities");
writableDatabase.execSQL("DELETE FROM countries");
writableDatabase.execSQL("DELETE FROM audio WHERE audio_id in (select au.audio_id from audio as au left join audio_cache as ac on ac.audio_id=au.audio_id where ac._id is NULL)");
writableDatabase.execSQL("DELETE FROM wall");
writableDatabase.execSQL("DELETE FROM graffiti");
writableDatabase.execSQL("DELETE FROM groups");
writableDatabase.execSQL("DELETE FROM user_group");
writableDatabase.execSQL("DELETE FROM video WHERE _id in (select v._id from video as v left join video_cache as vc on vc.video_id=v.video_id AND vc.owner_id=v.owner_id where vc._id is NULL)");
writableDatabase.execSQL("DELETE FROM wall_like");
writableDatabase.execSQL("DELETE FROM attachments");
writableDatabase.execSQL("DELETE FROM poll");
writableDatabase.execSQL("DELETE FROM chat");
writableDatabase.execSQL("DELETE FROM group_topics");
writableDatabase.execSQL("DELETE FROM chat_members");
writableDatabase.execSQL("DELETE FROM fave_users");
writableDatabase.execSQL("DELETE FROM fave_links");
writableDatabase.execSQL("DELETE FROM fave_posts");
writableDatabase.execSQL("DELETE FROM docs");
writableDatabase.execSQL("DELETE FROM albumphoto");
writableDatabase.execSQL("DELETE FROM video_in_album");
writableDatabase.execSQL("DELETE FROM audio_albums");
writableDatabase.execSQL("DELETE FROM audio_in_list");
writableDatabase.execSQL("DELETE FROM fave_groups");
writableDatabase.setTransactionSuccessful();
writableDatabase.endTransaction();
vacuum();
} catch (Throwable th) {
writableDatabase.endTransaction();
throw th;
}
}
public void clearVideoCache() {
this.mDbHelper.getWritableDatabase().execSQL("DELETE FROM video_cache");
}
public void close() {
this.mDbHelper.close();
}
public void createAdEvent(int i, int i2, int i3) {
ContentValues contentValues = new ContentValues();
contentValues.put("type", Integer.valueOf(i));
contentValues.put("ads_id1", Integer.valueOf(i2));
contentValues.put("ads_id2", Integer.valueOf(i3));
contentValues.put("date", Long.valueOf(millisToEventTime(System.currentTimeMillis())));
this.mDbHelper.getWritableDatabase().insertOrThrow("ad_events", null, contentValues);
}
public void createAlbum(Album album) {
ContentValues contentValues = new ContentValues();
contentValues.put("album_id", Long.valueOf(album.aid));
contentValues.put("owner_id", Long.valueOf(album.owner_id));
contentValues.put("title", album.title);
contentValues.put("description", album.description);
contentValues.put("size", Long.valueOf(album.size));
Privacy privacy = album.privacy;
if (privacy != null) {
contentValues.put("privacy_str", privacy.toString());
}
Privacy privacy2 = album.comment_privacy;
if (privacy2 != null) {
contentValues.put("privacy_comments", privacy2.toString());
}
String str = album.thumb_src;
if (str != null) {
contentValues.put("thumb_src", str);
}
this.mDbHelper.getWritableDatabase().insertOrThrow("albums", null, contentValues);
}
public void createAlbumPhoto(long j, long j2, long j3, long j4) {
ContentValues contentValues = new ContentValues();
contentValues.put("album_id", Long.valueOf(j2));
contentValues.put("album_owner_id", Long.valueOf(j3));
contentValues.put("photo_id", Long.valueOf(j));
contentValues.put("photo_owner_id", Long.valueOf(j4));
this.mDbHelper.getWritableDatabase().insertOrThrow("albumphoto", null, contentValues);
}
public void createAlbumPhotos(ArrayList arrayList, long j, long j2) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Photo photo = (Photo) it.next();
createAlbumPhoto(photo.pid, j, j2, Long.parseLong(photo.owner_id));
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createAlbums(ArrayList arrayList) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createAlbum((Album) it.next());
}
}
public void createAudio(Audio audio) {
ContentValues contentValues = new ContentValues();
contentValues.put("audio_id", Long.valueOf(audio.aid));
contentValues.put("owner_id", Long.valueOf(audio.owner_id));
contentValues.put("artist", audio.artist);
contentValues.put("title", audio.title);
contentValues.put("duration", Long.valueOf(audio.duration));
contentValues.put("url", audio.url);
contentValues.put("lyrics_id", audio.lyrics_id);
int i = audio.track_genre_id;
if (i != 0) {
contentValues.put("genre_id", Integer.valueOf(i));
}
this.mDbHelper.getWritableDatabase().insertOrThrow("audio", null, contentValues);
}
public void createAudioAlbum(AudioAlbum audioAlbum) {
ContentValues contentValues = new ContentValues();
contentValues.put("album_id", Long.valueOf(audioAlbum.album_id));
contentValues.put("owner_id", Long.valueOf(audioAlbum.owner_id));
contentValues.put("title", audioAlbum.title);
contentValues.put("photo", audioAlbum.photo);
this.mDbHelper.getWritableDatabase().insertOrThrow("audio_albums", null, contentValues);
}
public void createAudioAlbums(ArrayList arrayList) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createAudioAlbum((AudioAlbum) it.next());
}
}
public void createAudioInList(long j, long j2, long j3) {
ContentValues contentValues = new ContentValues();
contentValues.put("list_id", Long.valueOf(j2));
contentValues.put("list_owner_id", Long.valueOf(j3));
contentValues.put("audio_id", Long.valueOf(j));
this.mDbHelper.getWritableDatabase().insertOrThrow("audio_in_list", null, contentValues);
}
public void createAudiosInList(ArrayList arrayList, long j, long j2) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createAudioInList(((Audio) it.next()).aid, j, j2);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createChat(long j, String str, String str2, long j2, int i, long j3) {
ContentValues contentValues = new ContentValues();
contentValues.put("chat_id", Long.valueOf(j));
contentValues.put("title", str);
contentValues.put("photo_100", str2);
contentValues.put("account_id", Long.valueOf(j2));
contentValues.put("unread_count", Integer.valueOf(i));
contentValues.put("group_id", Long.valueOf(j3));
this.mDbHelper.getWritableDatabase().insert("chat", null, contentValues);
}
public void createChatMember(Long l, Long l2) {
ContentValues contentValues = new ContentValues();
contentValues.put("chat_id", l);
contentValues.put("user_id", l2);
this.mDbHelper.getWritableDatabase().insertOrThrow("chat_members", null, contentValues);
}
public void createChatMembers(Long l, ArrayList arrayList) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createChatMember(l, (Long) it.next());
}
}
public void createCity(long j, String str) {
ContentValues contentValues = new ContentValues();
contentValues.put("_id", Long.valueOf(j));
contentValues.put("name", str);
this.mDbHelper.getWritableDatabase().insert("cities", null, contentValues);
}
public void createComment(Comment comment, long j, long j2, long j3, long j4) {
ContentValues contentValues = new ContentValues();
contentValues.put("comment_id", Long.valueOf(comment.cid));
contentValues.put("date", Long.valueOf(comment.date));
contentValues.put("from_id", Long.valueOf(comment.from_id));
contentValues.put("message", comment.message);
contentValues.put("content_id", Long.valueOf(j));
contentValues.put("content_type", Long.valueOf(j2));
contentValues.put("content_owner_id", Long.valueOf(j3));
int i = comment.like_count;
if (i != 0) {
contentValues.put("like_count", Integer.valueOf(i));
}
long j5 = comment.reply_to_cid;
if (j5 != 0) {
contentValues.put("reply_to_cid", Long.valueOf(j5));
}
long j6 = comment.reply_to_uid;
if (j6 != 0) {
contentValues.put("reply_to_uid", Long.valueOf(j6));
}
int contentTypeToLikeType = contentTypeToLikeType(j2);
if (contentTypeToLikeType != -1) {
createOrUpdateWallLike(j3, comment.cid, j4, comment.user_like, contentTypeToLikeType);
}
this.mDbHelper.getWritableDatabase().insertOrThrow("comments", null, contentValues);
}
public void createCountry(long j, String str) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("_id", Long.valueOf(j));
contentValues.put("name", str);
writableDatabase.insert("countries", null, contentValues);
}
public void createCroupTopics(ArrayList arrayList) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createGroupTopic((GroupTopic) it.next());
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createDoc(Document document) {
ContentValues contentValues = new ContentValues();
contentValues.put("doc_id", Long.valueOf(document.id));
contentValues.put("owner_id", Long.valueOf(document.owner_id));
contentValues.put("title", document.title);
contentValues.put("size", Long.valueOf(document.size));
contentValues.put("ext", document.ext);
contentValues.put("url", document.url);
contentValues.put("thumb", document.thumb);
contentValues.put("thumb_s", document.thumb_o);
contentValues.put("title_lower", document.title.toLowerCase());
this.mDbHelper.getWritableDatabase().insertOrThrow("docs", null, contentValues);
}
public void createFaveGroup(long j, long j2) {
ContentValues contentValues = new ContentValues();
contentValues.put("account_id", Long.valueOf(j));
contentValues.put("group_id", Long.valueOf(j2));
this.mDbHelper.getWritableDatabase().insertOrThrow("fave_groups", null, contentValues);
}
public void createFaveGroups(ArrayList arrayList, long j) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
createOrUpdateGroups(arrayList);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createFaveGroup(j, ((Group) it.next()).gid);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createFaveLink(long j, Link link) {
ContentValues contentValues = new ContentValues();
contentValues.put("account_id", Long.valueOf(j));
contentValues.put("url", link.url);
contentValues.put("title", link.title);
contentValues.put("description", link.description);
contentValues.put("image_src", link.image_src);
contentValues.put("link_id", link.id);
this.mDbHelper.getWritableDatabase().insertOrThrow("fave_links", null, contentValues);
}
public void createFaveLinks(ArrayList arrayList, long j) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createFaveLink(j, (Link) it.next());
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createFavePosts(long j, long j2, long j3, boolean z) {
if (z) {
j = -j;
}
ContentValues contentValues = new ContentValues();
contentValues.put("account_id", Long.valueOf(j));
contentValues.put("post_id", Long.valueOf(j2));
contentValues.put("owner_id", Long.valueOf(j3));
this.mDbHelper.getWritableDatabase().insertOrThrow("fave_posts", null, contentValues);
}
public void createFavePosts(ArrayList arrayList, long j, boolean z) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
createOrUpdateWallPosts(arrayList, j);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
WallMessage wallMessage = (WallMessage) it.next();
createFavePosts(j, wallMessage.id, wallMessage.to_id, z);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createFaveUser(long j, long j2) {
ContentValues contentValues = new ContentValues();
contentValues.put("account_id", Long.valueOf(j));
contentValues.put("user_id", Long.valueOf(j2));
this.mDbHelper.getWritableDatabase().insertOrThrow("fave_users", null, contentValues);
}
public void createFaveUsers(ArrayList arrayList, long j) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
createOrUpdateUsers(arrayList);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createFaveUser(j, ((User) it.next()).uid);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createFriend(long j, long j2) {
ContentValues contentValues = new ContentValues();
contentValues.put("owner_id", Long.valueOf(j));
contentValues.put("friend_id", Long.valueOf(j2));
this.mDbHelper.getWritableDatabase().insertOrThrow("friends", null, contentValues);
}
public void createFriends(ArrayList arrayList, long j) {
long nanoTime = System.nanoTime();
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
deleteAllFriends(j);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateUser((User) it.next(), false);
}
createFriendsInternal(j, arrayList);
writableDatabase.setTransactionSuccessful();
writableDatabase.endTransaction();
long nanoTime2 = System.nanoTime();
Log.i("Kate.DataHelper", "createFriends duration " + ((nanoTime2 - nanoTime) / 1000000) + " ms");
} catch (Throwable th) {
writableDatabase.endTransaction();
throw th;
}
}
public void createGroup(Group group) {
ContentValues contentValues = new ContentValues();
contentValues.put("_id", Long.valueOf(group.gid));
String str = group.name;
if (str != null) {
contentValues.put("name", str);
contentValues.put("name_lower", group.name.toLowerCase());
}
String str2 = group.photo;
if (str2 != null) {
contentValues.put("photo", str2);
}
String str3 = group.photo_medium;
if (str3 != null) {
contentValues.put("photo_medium", str3);
}
String str4 = group.photo_big;
if (str4 != null) {
contentValues.put("photo_big", str4);
}
Integer num = group.is_closed;
if (num != null) {
contentValues.put("is_closed", num);
}
String str5 = group.description;
if (str5 != null) {
contentValues.put("description", str5);
}
String str6 = group.wiki_page;
if (str6 != null) {
contentValues.put("wiki", str6);
}
Long l = group.fixed_post;
if (l != null) {
contentValues.put("fixed_post", l);
}
Boolean bool = group.can_see_all_posts;
if (bool != null) {
contentValues.put("can_see_all_posts", bool);
}
Integer num2 = group.members_count;
if (num2 != null) {
contentValues.put("members_count", num2);
}
Integer num3 = group.type;
if (num3 != null) {
contentValues.put("type", num3);
}
Long l2 = group.start_date;
if (l2 != null) {
contentValues.put("start_date", l2);
}
String str7 = group.status;
if (str7 != null) {
contentValues.put("status", str7);
}
Integer num4 = group.photos_count;
if (num4 != null) {
contentValues.put("photos", num4);
}
Integer num5 = group.albums_count;
if (num5 != null) {
contentValues.put("albums", num5);
}
Integer num6 = group.topics_count;
if (num6 != null) {
contentValues.put("topics", num6);
}
Integer num7 = group.videos_count;
if (num7 != null) {
contentValues.put("videos", num7);
}
Integer num8 = group.audios_count;
if (num8 != null) {
contentValues.put("audios", num8);
}
Integer num9 = group.docs_count;
if (num9 != null) {
contentValues.put("docs", num9);
}
Integer num10 = group.podcasts_count;
if (num10 != null) {
contentValues.put("podcasts", num10);
}
Integer num11 = group.verified;
if (num11 != null) {
contentValues.put("verified", num11);
}
Boolean bool2 = group.can_message;
if (bool2 != null) {
contentValues.put("can_message", bool2);
}
Boolean bool3 = group.market_enabled;
if (bool3 != null) {
contentValues.put("market_enabled", bool3);
}
Long l3 = group.market_contact_id;
if (l3 != null) {
contentValues.put("market_contact_id", l3);
}
Page page = group.market_wiki;
if (page != null) {
contentValues.put("market_wiki_id", Long.valueOf(page.id));
contentValues.put("market_wiki_title", group.market_wiki.title);
}
String str8 = group.cover_400;
if (str8 != null) {
contentValues.put("cover_400", str8);
}
String str9 = group.cover_800;
if (str9 != null) {
contentValues.put("cover_800", str9);
}
this.mDbHelper.getWritableDatabase().insertOrThrow("groups", null, contentValues);
}
public void createGroupTopic(GroupTopic groupTopic) {
ContentValues contentValues = new ContentValues();
contentValues.put("_id", Long.valueOf(groupTopic.tid));
contentValues.put("group_id", Long.valueOf(groupTopic.gid));
contentValues.put("title", groupTopic.title);
contentValues.put("title_lower", groupTopic.title.toLowerCase());
contentValues.put("comments", Integer.valueOf(groupTopic.comments));
contentValues.put("created", Long.valueOf(groupTopic.created));
contentValues.put("created_by", Long.valueOf(groupTopic.created_by));
contentValues.put("updated", Long.valueOf(groupTopic.updated));
contentValues.put("updated_by", Long.valueOf(groupTopic.updated_by));
contentValues.put("is_closed", Integer.valueOf(groupTopic.is_closed));
contentValues.put("is_fixed", Integer.valueOf(groupTopic.is_fixed));
this.mDbHelper.getWritableDatabase().insertOrThrow("group_topics", null, contentValues);
}
public void createMessage(Message message, long j, long j2) {
ContentValues contentValues = new ContentValues();
contentValues.put("message_id", Long.valueOf(message.mid));
contentValues.put("account_id", Long.valueOf(j));
contentValues.put("group_id", Long.valueOf(j2));
contentValues.put("date", Long.valueOf(message.date));
contentValues.put("uid", Long.valueOf(message.uid));
contentValues.put("title", message.title);
contentValues.put("body", message.body);
contentValues.put("read_state", Integer.valueOf(message.read_state ? 1 : 0));
contentValues.put("is_out", Boolean.valueOf(message.is_out));
contentValues.put("have_attachments", Integer.valueOf(message.attachments.size() > 0 ? 1 : 0));
Boolean bool = message.important;
if (bool != null) {
contentValues.put("important", Integer.valueOf(bool.booleanValue() ? 1 : 0));
}
contentValues.put("chat_id", Long.valueOf(ThreadIdHelper.makeThreadId(message.chat_id, Long.valueOf(message.uid))));
Integer num = message.action;
if (num != null) {
contentValues.put("action", num);
}
Long l = message.action_mid;
if (l != null) {
contentValues.put("action_mid", l);
}
String str = message.action_text;
if (str != null) {
contentValues.put("action_text", str);
}
long j3 = message.update_time;
if (j3 != 0) {
contentValues.put("update_time", Long.valueOf(j3));
}
contentValues.put("attachments", serializeAttachments(message.attachments));
this.mDbHelper.getWritableDatabase().insertOrThrow("messages", null, contentValues);
}
public void createNews(Newsfeed newsfeed, long j, int i) {
long currentTimeMillis = System.currentTimeMillis();
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
createNewsInternal(newsfeed, j, i);
writableDatabase.setTransactionSuccessful();
writableDatabase.endTransaction();
long currentTimeMillis2 = System.currentTimeMillis();
Log.i("Kate.DataHelper", "create news duration=" + (currentTimeMillis2 - currentTimeMillis));
} catch (Throwable th) {
writableDatabase.endTransaction();
throw th;
}
}
public void createNewsItem(NewsItem newsItem, long j, int i) {
ContentValues contentValues = new ContentValues();
contentValues.put("account_id", Long.valueOf(j));
contentValues.put("comment_can_post", Boolean.valueOf(newsItem.comment_can_post));
contentValues.put("comment_count", Integer.valueOf(newsItem.comment_count));
contentValues.put("copy_owner_id", Long.valueOf(newsItem.copy_owner_id));
contentValues.put("copy_post_id", Long.valueOf(newsItem.copy_post_id));
contentValues.put("copy_text", newsItem.copy_text);
contentValues.put("like_count", Integer.valueOf(newsItem.like_count));
contentValues.put("post_id", Long.valueOf(newsItem.post_id));
contentValues.put("source_id", Long.valueOf(newsItem.source_id));
contentValues.put("from_id", Long.valueOf(newsItem.from_id));
contentValues.put("date", Long.valueOf(newsItem.date));
contentValues.put("text", newsItem.text);
contentValues.put("type", newsItem.type);
contentValues.put("user_like", Boolean.valueOf(newsItem.user_like));
contentValues.put("is_comments", Integer.valueOf(i));
contentValues.put("comments", newsItem.comments_json);
contentValues.put("signer_id", Long.valueOf(newsItem.signer_id));
contentValues.put("reposts_count", Integer.valueOf(newsItem.reposts_count));
contentValues.put("user_reposted", Boolean.valueOf(newsItem.user_reposted));
Integer num = newsItem.views;
if (num != null) {
contentValues.put("views", num);
}
String str = newsItem.ads_title;
if (str != null) {
contentValues.put("ads_title", str);
}
String str2 = newsItem.age_restriction;
if (str2 != null) {
contentValues.put("age_restriction", str2);
}
String str3 = newsItem.ad_data;
if (str3 != null) {
contentValues.put("ad_data", str3);
}
String str4 = newsItem.ad_data_impression;
if (str4 != null) {
contentValues.put("ad_data_impression", str4);
}
List list = newsItem.statistics;
if (list != null) {
contentValues.put("statistics", serializeStats(list));
}
String str5 = newsItem.track_code;
if (str5 != null) {
contentValues.put("track_code", str5);
}
String str6 = newsItem.advertiser_info_url;
if (str6 != null) {
contentValues.put("advertiser_info_url", str6);
}
Integer num2 = newsItem.ads_id1;
if (num2 != null) {
contentValues.put("ads_id1", num2);
}
Integer num3 = newsItem.ads_id2;
if (num3 != null) {
contentValues.put("ads_id2", num3);
}
contentValues.put("attachments", serializeAttachments(newsItem.attachments));
String str7 = newsItem.copyright_link;
if (str7 != null) {
contentValues.put("copyright_link", str7);
}
String str8 = newsItem.copyright_name;
if (str8 != null) {
contentValues.put("copyright_name", str8);
}
this.mDbHelper.getWritableDatabase().insertOrThrow("news", null, contentValues);
}
public void createNote(Note note) {
ContentValues contentValues = new ContentValues();
contentValues.put("_id", Long.valueOf(note.nid));
String str = note.text;
if (str != null) {
contentValues.put("text", str);
}
contentValues.put("title", note.title);
contentValues.put("comments", Long.valueOf(note.ncom));
contentValues.put("date", Long.valueOf(note.date));
contentValues.put("from_id", Long.valueOf(note.owner_id));
this.mDbHelper.getWritableDatabase().insertOrThrow("notes", null, contentValues);
}
public void createOrUpdateAudio(Audio audio) {
if (updateAudio(audio)) {
return;
}
createAudio(audio);
}
public void createOrUpdateAudios(ArrayList arrayList) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateAudio((Audio) it.next());
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createOrUpdateCroupTopics(ArrayList arrayList) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateGroupTopic((GroupTopic) it.next());
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createOrUpdateDialogs(ArrayList arrayList, long j, boolean z, long j2, Collection collection) {
ArrayList<Long> arrayList2;
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
if (z) {
String str = "";
if (collection != null) {
try {
if (collection.size() != 0) {
str = " AND chat_id not in(" + TextUtils.join(",", collection) + ") ";
}
} finally {
writableDatabase.endTransaction();
}
}
writableDatabase.execSQL("DELETE FROM chat WHERE account_id=? AND group_id=?" + str, new String[]{Long.toString(j), Long.toString(j2)});
}
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Message message = (Message) it.next();
createOrUpdateMessage(message, j, false, j2);
Long l = message.chat_id;
if (l != null && l.longValue() > 0 && (arrayList2 = message.chat_members) != null) {
recreateChatMembers(message.chat_id, arrayList2);
}
long makeThreadId = ThreadIdHelper.makeThreadId(message.chat_id, Long.valueOf(message.uid));
if (!updateChat(message, makeThreadId, j, j2)) {
createChat(makeThreadId, message.title, message.photo_100, j, message.unread_count, j2);
}
}
writableDatabase.setTransactionSuccessful();
}
public void createOrUpdateGroup(Group group, boolean z) {
if (updateGroup(group, z)) {
return;
}
createGroup(group);
}
public void createOrUpdateGroups(ArrayList arrayList) {
if (arrayList == null) {
return;
}
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateGroup((Group) it.next(), false);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public boolean createOrUpdateMessage(Message message, long j, boolean z, long j2) {
createAttachedObjects(message.attachments, j);
if (updateMessage(message, j, j2)) {
return false;
}
createMessage(message, j, j2);
long makeThreadId = ThreadIdHelper.makeThreadId(message.chat_id, Long.valueOf(message.uid));
if (z) {
ensureChatExists(makeThreadId, j, j2);
}
return true;
}
public void createOrUpdateMessages(ArrayList arrayList, long j, long j2) {
createOrUpdateMessages(arrayList, j, false, j2);
}
public boolean createOrUpdateMessages(ArrayList arrayList, long j, boolean z, long j2) {
boolean z2;
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
boolean z3 = false;
try {
Iterator it = arrayList.iterator();
z2 = false;
while (it.hasNext()) {
try {
z2 |= createOrUpdateMessage((Message) it.next(), j, z, j2);
} catch (Throwable th) {
th = th;
z3 = z2;
try {
th.printStackTrace();
Helper.reportError(th);
z2 = z3;
writableDatabase.setTransactionSuccessful();
return z2;
} finally {
writableDatabase.endTransaction();
}
}
}
} catch (Throwable th2) {
th = th2;
}
writableDatabase.setTransactionSuccessful();
return z2;
}
public void createOrUpdateNote(Note note) {
if (updateNote(note)) {
return;
}
createNote(note);
}
public void createOrUpdatePhoto(Photo photo, long j) {
if (!updatePhoto(photo)) {
createPhoto(photo);
}
if (photo.user_likes != null) {
createOrUpdateWallLike(Long.parseLong(photo.owner_id), photo.pid, j, photo.user_likes.booleanValue(), 1);
}
}
public void createOrUpdatePhotos(ArrayList arrayList, long j) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdatePhoto((Photo) it.next(), j);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createOrUpdatePoll(VkPoll vkPoll, long j) {
if (updatePoll(vkPoll, j)) {
return;
}
createPoll(vkPoll, j);
}
public void createOrUpdateUser(User user, boolean z) {
if (updateUser(user, z)) {
return;
}
createUser(user);
}
public void createOrUpdateUsers(ArrayList arrayList) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateUser((User) it.next(), false);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createOrUpdateVideo(Video video) {
if (updateVideo(video)) {
return;
}
createVideo(video);
}
public void createOrUpdateVideoUserLikes(ArrayList arrayList, long j) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Video video = (Video) it.next();
Boolean bool = video.user_likes;
if (bool != null) {
createOrUpdateWallLike(video.owner_id, video.vid, j, bool.booleanValue(), 6);
}
}
}
public void createOrUpdateVideos(ArrayList arrayList) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateVideo((Video) it.next());
}
}
public void createOrUpdateWallLike(long j, long j2, long j3, boolean z, int i) {
createOrUpdateWallLike(j, j2, j3, z, i, null);
}
public void createOrUpdateWallLike(long j, long j2, long j3, boolean z, int i, Boolean bool) {
if (updateWallLike(j, j2, j3, z, i, bool) == 0 && z) {
createWallLike(j, j2, j3, z, i, bool);
}
}
public void createOrUpdateWallPost(WallMessage wallMessage, long j, boolean z) {
repostCompatibilityHack(wallMessage);
ArrayList<Attachment> arrayList = wallMessage.attachments;
if (arrayList != null) {
createAttachedObjects(arrayList, j);
}
Long fetchWallPost = z ? fetchWallPost(wallMessage.id, wallMessage.to_id) : null;
if (fetchWallPost == null) {
createWallPost(wallMessage, j);
} else {
updateWallPost(wallMessage, j, fetchWallPost.longValue());
}
}
public void createOrUpdateWallPosts(ArrayList arrayList, long j) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateWallPost((WallMessage) it.next(), j, true);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void createPhoto(Photo photo) {
ContentValues contentValues = new ContentValues();
contentValues.put("photo_id", Long.valueOf(photo.pid));
contentValues.put("owner_id", photo.owner_id);
contentValues.put("album_id", Long.valueOf(photo.aid));
contentValues.put("src", photo.src);
contentValues.put("src_big", photo.src_big);
contentValues.put("src_xbig", photo.src_xbig);
contentValues.put("src_xxbig", photo.src_xxbig);
contentValues.put("src_xxxbig", photo.src_xxxbig);
contentValues.put("phototext", photo.phototext);
contentValues.put("created", Long.valueOf(photo.created));
Integer num = photo.like_count;
if (num != null) {
contentValues.put("like_count", num);
}
Integer num2 = photo.comments_count;
if (num2 != null) {
contentValues.put("comments_count", num2);
}
contentValues.put("width", Integer.valueOf(photo.width));
contentValues.put("height", Integer.valueOf(photo.height));
String str = photo.lat;
if (str != null) {
contentValues.put("lat", str);
}
String str2 = photo.lon;
if (str2 != null) {
contentValues.put("lon", str2);
}
this.mDbHelper.getWritableDatabase().insertOrThrow("photos", null, contentValues);
}
public void createPoll(VkPoll vkPoll, long j) {
ContentValues contentValues = new ContentValues();
contentValues.put("poll_id", Long.valueOf(vkPoll.id));
contentValues.put("owner_id", Long.valueOf(vkPoll.owner_id));
contentValues.put("account_id", Long.valueOf(j));
contentValues.put("question", vkPoll.question);
contentValues.put("anonymous", Integer.valueOf(vkPoll.anonymous ? 1 : 0));
this.mDbHelper.getWritableDatabase().insertOrThrow("poll", null, contentValues);
}
public void createUser(User user) {
ContentValues contentValues = new ContentValues();
contentValues.put("_id", Long.valueOf(user.uid));
contentValues.put("is_full", (Integer) 1);
String str = user.first_name;
if (str != null) {
contentValues.put("first_name", str);
contentValues.put("first_name_lower", user.first_name.toLowerCase());
}
String str2 = user.last_name;
if (str2 != null) {
contentValues.put("last_name", str2);
contentValues.put("last_name_lower", user.last_name.toLowerCase());
}
String str3 = user.nickname;
if (str3 != null) {
contentValues.put("nickname", str3);
contentValues.put("nickname_lower", user.nickname.toLowerCase());
}
contentValues.put("photo", user.photo);
contentValues.put("photo_medium_rec", user.photo_medium_rec);
contentValues.put("photo_big", user.photo_big);
String str4 = user.photo_200;
if (str4 != null) {
contentValues.put("photo_200", str4);
}
String str5 = user.photo_400_orig;
if (str5 != null) {
contentValues.put("photo_400_orig", str5);
}
contentValues.put("domain", user.domain);
contentValues.put("sex", user.sex);
contentValues.put("birthdate", user.birthdate);
contentValues.put("city", user.city);
contentValues.put("country", user.country);
contentValues.put("rate", user.rate);
contentValues.put("mobile_phone", user.mobile_phone);
contentValues.put("home_phone", user.home_phone);
contentValues.put("university", user.university);
contentValues.put("university_name", user.university_name);
contentValues.put("faculty", user.faculty);
contentValues.put("faculty_name", user.faculty_name);
contentValues.put("graduation", user.graduation);
Boolean bool = user.online;
if (bool != null) {
contentValues.put("online", Integer.valueOf(bool.booleanValue() ? 1 : 0));
}
Boolean bool2 = user.online_mobile;
if (bool2 != null) {
contentValues.put("online_mobile", Integer.valueOf(bool2.booleanValue() ? 1 : 0));
}
contentValues.put("status", user.status);
Integer num = user.relation;
if (num != null) {
contentValues.put("relation", num);
}
contentValues.put("last_seen", Long.valueOf(user.last_seen));
contentValues.put("albums", Integer.valueOf(user.albums_count));
contentValues.put("photos", Integer.valueOf(user.photo_count));
contentValues.put("videos", Integer.valueOf(user.videos_count));
contentValues.put("audios", Integer.valueOf(user.audios_count));
contentValues.put("notes", Integer.valueOf(user.notes_count));
contentValues.put("friends", Integer.valueOf(user.friends_count));
contentValues.put("online_friends", user.online_friends_count);
Integer num2 = user.mutual_friends_count;
if (num2 != null) {
contentValues.put("mutual_friends", num2);
}
contentValues.put("user_photos", Integer.valueOf(user.user_photos_count));
contentValues.put("groups", Integer.valueOf(user.groups_count));
contentValues.put("followers", Integer.valueOf(user.followers_count));
contentValues.put("gifts", Integer.valueOf(user.gifts_count));
Integer num3 = user.verified;
if (num3 != null) {
contentValues.put("verified", num3);
}
User.Rect rect = user.crop_photo_rect;
if (rect != null) {
contentValues.put("crop_photo_rect_x1", Double.valueOf(rect.x1));
contentValues.put("crop_photo_rect_x2", Double.valueOf(user.crop_photo_rect.x2));
contentValues.put("crop_photo_rect_y1", Double.valueOf(user.crop_photo_rect.y1));
contentValues.put("crop_photo_rect_y2", Double.valueOf(user.crop_photo_rect.y2));
}
String str6 = user.cover_400;
if (str6 != null) {
contentValues.put("cover_400", str6);
}
String str7 = user.cover_960;
if (str7 != null) {
contentValues.put("cover_960", str7);
}
this.mDbHelper.getWritableDatabase().insertOrThrow("users", null, contentValues);
}
public void createUserDocs(ArrayList arrayList, long j, boolean z) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
if (z) {
try {
deleteDocs(j);
} finally {
writableDatabase.endTransaction();
}
}
Iterator it = arrayList.iterator();
while (it.hasNext()) {
try {
createDoc((Document) it.next());
} catch (SQLiteConstraintException e) {
e.printStackTrace();
Helper.reportError(e);
}
}
writableDatabase.setTransactionSuccessful();
}
public void createUserGroup(long j, long j2, Boolean bool, Integer num) {
ContentValues contentValues = new ContentValues();
contentValues.put("user_id", Long.valueOf(j));
contentValues.put("group_id", Long.valueOf(j2));
if (bool != null && !bool.booleanValue()) {
num = 0;
}
if (num != null) {
contentValues.put("admin_level", num);
}
this.mDbHelper.getWritableDatabase().insertOrThrow("user_group", null, contentValues);
}
public void createUserGroups(ArrayList arrayList, long j, boolean z) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
if (z) {
try {
deleteUserGroups(j);
} finally {
writableDatabase.endTransaction();
}
}
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Group group = (Group) it.next();
createOrUpdateGroup(group, false);
createUserGroup(j, group.gid, group.is_admin, group.admin_level);
}
writableDatabase.setTransactionSuccessful();
}
public void createUserNotes(ArrayList arrayList, long j) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
deleteNotes(j);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createNote((Note) it.next());
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
void createVideo(Video video) {
ContentValues contentValues = new ContentValues();
contentValues.put("video_id", Long.valueOf(video.vid));
contentValues.put("owner_id", Long.valueOf(video.owner_id));
contentValues.put("title", video.title);
contentValues.put("description", video.description);
contentValues.put("duration", Long.valueOf(video.duration));
contentValues.put("image", video.image);
contentValues.put("image_big", video.image_big);
contentValues.put("date", Long.valueOf(video.date));
contentValues.put("player_url", video.player);
contentValues.put("views", Integer.valueOf(video.views));
Integer num = video.like_count;
if (num != null) {
contentValues.put("likes_count", num);
}
contentValues.put("platform", video.platform);
this.mDbHelper.getWritableDatabase().insertOrThrow("video", null, contentValues);
}
public void createVideoInAlbum(long j, long j2, long j3, long j4) {
ContentValues contentValues = new ContentValues();
contentValues.put("album_id", Long.valueOf(j));
contentValues.put("album_owner_id", Long.valueOf(j2));
contentValues.put("video_id", Long.valueOf(j3));
contentValues.put("video_owner_id", Long.valueOf(j4));
this.mDbHelper.getWritableDatabase().insertOrThrow("video_in_album", null, contentValues);
}
public void createVideosInAlbum(long j, long j2, ArrayList arrayList) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Video video = (Video) it.next();
createVideoInAlbum(j2, j, video.vid, video.owner_id);
}
}
public void createWallLike(long j, long j2, long j3, boolean z, int i, Boolean bool) {
ContentValues contentValues = new ContentValues();
contentValues.put("wall_owner_id", Long.valueOf(j));
contentValues.put("post_id", Long.valueOf(j2));
contentValues.put("account_id", Long.valueOf(j3));
contentValues.put("like", Integer.valueOf(z ? 1 : 0));
if (bool != null) {
contentValues.put("reposted", Integer.valueOf(bool.booleanValue() ? 1 : 0));
}
contentValues.put("type", Integer.valueOf(i));
this.mDbHelper.getWritableDatabase().insertOrThrow("wall_like", null, contentValues);
}
public void createWallPost(WallMessage wallMessage, long j) {
ContentValues contentValues = new ContentValues();
contentValues.put("post_id", Long.valueOf(wallMessage.id));
contentValues.put("from_id", Long.valueOf(wallMessage.from_id));
contentValues.put("to_id", Long.valueOf(wallMessage.to_id));
contentValues.put("date", Long.valueOf(wallMessage.date));
contentValues.put("text", wallMessage.text);
contentValues.put("comments_count", Long.valueOf(wallMessage.comment_count));
contentValues.put("copy_owner_id", Long.valueOf(wallMessage.copy_owner_id));
contentValues.put("copy_text", wallMessage.copy_text);
contentValues.put("signer_id", Long.valueOf(wallMessage.signer_id));
contentValues.put("post_type", Integer.valueOf(wallMessage.post_type));
Integer num = wallMessage.views;
if (num != null) {
contentValues.put("views", num);
}
contentValues.put("likes_count", Integer.valueOf(wallMessage.like_count));
createOrUpdateWallLike(wallMessage.to_id, wallMessage.id, j, wallMessage.user_like, 0, Boolean.valueOf(wallMessage.user_reposted));
contentValues.put("reposts_count", Integer.valueOf(wallMessage.reposts_count));
contentValues.put("is_pinned", Integer.valueOf(wallMessage.is_pinned ? 1 : 0));
String str = wallMessage.copyright_link;
if (str != null) {
contentValues.put("copyright_link", str);
}
String str2 = wallMessage.copyright_name;
if (str2 != null) {
contentValues.put("copyright_name", str2);
}
contentValues.put("created_by", Long.valueOf(wallMessage.created_by));
contentValues.put("attachments", serializeAttachments(wallMessage.attachments));
this.mDbHelper.getWritableDatabase().insertOrThrow("wall", null, contentValues);
}
public void deleteAlbum(long j) {
this.mDbHelper.getWritableDatabase().delete("albums", "album_id=?", new String[]{Long.toString(j)});
}
public void deleteAlbumPhoto(long j, long j2, long j3, long j4) {
this.mDbHelper.getWritableDatabase().delete("albumphoto", "album_id=? AND album_owner_id=? AND photo_id=? AND photo_owner_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3), Long.toString(j4)});
}
public void deleteAlbumPhotos(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("albumphoto", "album_id=? AND album_owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteAllFriends(long j) {
this.mDbHelper.getWritableDatabase().delete("friends", "owner_id=?", toArg(j));
}
public void deleteAllNews(long j, int i) {
this.mDbHelper.getWritableDatabase().delete("news", "account_id=? AND is_comments=?", new String[]{Long.toString(j), Integer.toString(i)});
}
public void deleteAndCreateNews(Newsfeed newsfeed, long j, int i) {
long currentTimeMillis = System.currentTimeMillis();
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
deleteAllNews(j, i);
createNewsInternal(newsfeed, j, i);
writableDatabase.setTransactionSuccessful();
writableDatabase.endTransaction();
long currentTimeMillis2 = System.currentTimeMillis();
Log.i("Kate.DataHelper", "deleteAndCreateNews duration=" + (currentTimeMillis2 - currentTimeMillis) + " ms");
} catch (Throwable th) {
writableDatabase.endTransaction();
throw th;
}
}
public void deleteAudioAlbums(long j) {
this.mDbHelper.getWritableDatabase().delete("audio_albums", "owner_id=?", toArg(j));
}
public void deleteAudioInList(long j, long j2, long j3) {
this.mDbHelper.getWritableDatabase().delete("audio_in_list", "list_id=? AND list_owner_id=? AND audio_id=?", new String[]{Long.toString(j2), Long.toString(j3), Long.toString(j)});
}
public void deleteAudiosInList(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("audio_in_list", "list_id=? AND list_owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteChatMember(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("chat_members", "chat_id=? AND user_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteChatMembers(long j) {
this.mDbHelper.getWritableDatabase().delete("chat_members", "chat_id= ?", toArg(j));
}
public void deleteChatMessages(long j, long j2, long j3) {
this.mDbHelper.getWritableDatabase().delete("messages", "chat_id=? AND account_id=? AND group_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public void deleteComment(long j, long j2, long j3, long j4) {
this.mDbHelper.getWritableDatabase().delete("comments", "content_id=? AND content_type=? AND content_owner_id=? AND comment_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3), Long.toString(j4)});
}
public void deleteComments(long j, long j2, long j3) {
this.mDbHelper.getWritableDatabase().delete("comments", "content_id=? AND content_type=? AND content_owner_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public void deleteDoc(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("docs", "doc_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteDocs(long j) {
this.mDbHelper.getWritableDatabase().delete("docs", "owner_id=?", toArg(j));
}
public void deleteFaveGroups(long j) {
this.mDbHelper.getWritableDatabase().delete("fave_groups", "account_id=?", toArg(j));
}
public void deleteFaveLinks(long j) {
this.mDbHelper.getWritableDatabase().delete("fave_links", "account_id=?", toArg(j));
}
public void deleteFavePost(long j, boolean z, long j2, long j3) {
if (z) {
j = -j;
}
this.mDbHelper.getWritableDatabase().delete("fave_posts", "account_id=? AND post_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public void deleteFavePosts(long j, boolean z) {
if (z) {
j = -j;
}
this.mDbHelper.getWritableDatabase().delete("fave_posts", "account_id=?", toArg(j));
}
public void deleteFaveUsers(long j) {
this.mDbHelper.getWritableDatabase().delete("fave_users", "account_id=?", toArg(j));
}
public void deleteFriend(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("friends", "owner_id=? AND friend_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteGroupTopic(long j) {
this.mDbHelper.getWritableDatabase().delete("group_topics", "_id=?", toArg(j));
}
public void deleteGroupTopics(long j) {
this.mDbHelper.getWritableDatabase().delete("group_topics", "group_id=?", toArg(j));
}
public void deleteMessage(long j, long j2, long j3) {
this.mDbHelper.getWritableDatabase().delete("messages", "message_id=? AND account_id=? AND group_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public void deleteMessageThread(long j, long j2, long j3, long j4) {
deleteChatMessages(ThreadIdHelper.makeThreadId(Long.valueOf(j2), Long.valueOf(j)), j3, j4);
}
public void deleteNewsFromOwnerId(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("news", "account_id=? AND (source_id=? OR copy_owner_id=?)", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j2)});
}
public void deleteNewsItem(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("news", "_id=? AND account_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteNote(long j) {
this.mDbHelper.getWritableDatabase().delete("notes", "_id=?", toArg(j));
}
public void deleteNotes(long j) {
this.mDbHelper.getWritableDatabase().delete("notes", "from_id=?", toArg(j));
}
public void deletePhoto(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("photos", "owner_id=? AND photo_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteUserAlbums(long j) {
this.mDbHelper.getWritableDatabase().delete("albums", "owner_id=?", toArg(j));
}
public void deleteUserGroup(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("user_group", "user_id=? AND group_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteUserGroups(long j) {
this.mDbHelper.getWritableDatabase().delete("user_group", "user_id=?", toArg(j));
}
public void deleteVideo(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("video", "video_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteVideosInAlbum(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("video_in_album", "album_id=? AND album_owner_id=?", new String[]{Long.toString(j2), Long.toString(j)});
}
public void deleteWallPost(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("wall", "post_id=? AND to_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void deleteWallPosts(long j) {
this.mDbHelper.getWritableDatabase().delete("wall", "to_id=?", toArg(j));
}
public boolean doesMessageExist(long j, String str, long j2) {
if (str == null) {
return false;
}
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT count(*) FROM messages WHERE account_id=? and group_id=0 and message_id=? AND body=?", new String[]{Long.toString(j2), Long.toString(j), str});
rawQuery.moveToFirst();
long j3 = rawQuery.getLong(0);
rawQuery.close();
return j3 > 0;
}
public void ensureChatExists(long j, long j2, long j3) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT EXISTS (SELECT _id FROM chat WHERE chat_id=? AND account_id=? AND group_id=?)", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
rawQuery.moveToFirst();
boolean z = rawQuery.getInt(0) == 1;
rawQuery.close();
if (z) {
return;
}
createChat(j, null, null, j2, 1, j3);
}
public Album fetchAlbum(long j) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT a.title, a.description, a.privacy_str, a.privacy_comments FROM albums as a WHERE a.album_id=?", toArg(j));
if (rawQuery == null) {
return null;
}
rawQuery.moveToFirst();
if (rawQuery.getCount() == 0) {
rawQuery.close();
return null;
}
Album album = new Album();
album.aid = j;
album.title = rawQuery.getString(rawQuery.getColumnIndex("title"));
album.description = rawQuery.getString(rawQuery.getColumnIndex("description"));
album.privacy = Privacy.parseString(rawQuery.getString(rawQuery.getColumnIndex("privacy_str")));
album.comment_privacy = Privacy.parseString(rawQuery.getString(rawQuery.getColumnIndex("privacy_comments")));
rawQuery.close();
return album;
}
public Album fetchAlbum(long j, long j2) {
Cursor cursor;
try {
cursor = this.mDbHelper.getWritableDatabase().rawQuery("SELECT a.title, a.description FROM albums as a WHERE a.album_id=? AND a.owner_id=? LIMIT 1", new String[]{Long.toString(j), Long.toString(j2)});
try {
if (cursor.getCount() == 0) {
cursor.close();
return null;
}
cursor.moveToFirst();
Album album = new Album();
album.title = cursor.getString(0);
album.description = cursor.getString(1);
cursor.close();
return album;
} catch (Throwable th) {
th = th;
try {
th.printStackTrace();
Helper.reportError(th);
return null;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
} catch (Throwable th2) {
th = th2;
cursor = null;
}
}
public Cursor fetchAlbums(long j) {
return this.mDbHelper.getWritableDatabase().rawQuery("SELECT a.album_id, a.title, /*a.description,*/ a.thumb_src, a.size FROM albums as a WHERE a.owner_id=? ORDER BY a._id", toArg(j));
}
public Audio fetchAudio(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("audio", new String[]{"artist", "duration", "lyrics_id", "title", "url"}, "audio_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Audio audio = new Audio();
audio.aid = j;
audio.artist = query.getString(0);
audio.duration = query.getLong(1);
audio.lyrics_id = Long.valueOf(query.getLong(2));
audio.owner_id = j2;
audio.title = query.getString(3);
audio.url = query.getString(4);
query.close();
return audio;
}
public AudioAlbum fetchAudioAlbum(long j, long j2) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT a.title FROM audio_albums as a WHERE a.owner_id=? AND a.album_id=?", new String[]{Long.toString(j), Long.toString(j2)});
AudioAlbum audioAlbum = null;
if (rawQuery == null) {
return null;
}
if (rawQuery.getCount() > 0) {
rawQuery.moveToFirst();
audioAlbum = new AudioAlbum();
audioAlbum.album_id = j2;
audioAlbum.owner_id = j;
audioAlbum.title = rawQuery.getString(0);
}
rawQuery.close();
return audioAlbum;
}
public ArrayList fetchAudioAlbums(long j) {
ArrayList arrayList = new ArrayList();
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT a.album_id, a.title, a.photo FROM audio_albums as a WHERE a.owner_id=?", toArg(j));
if (rawQuery == null) {
return arrayList;
}
while (rawQuery.moveToNext()) {
AudioAlbum audioAlbum = new AudioAlbum();
audioAlbum.album_id = rawQuery.getLong(0);
audioAlbum.owner_id = j;
audioAlbum.title = rawQuery.getString(1);
audioAlbum.photo = rawQuery.getString(2);
arrayList.add(audioAlbum);
}
rawQuery.close();
return arrayList;
}
public ArrayList fetchAudioInList(long j, long j2) {
Cursor fetchAudioInListCursor = fetchAudioInListCursor(j, j2);
ArrayList audioCursorToArray = audioCursorToArray(fetchAudioInListCursor);
fetchAudioInListCursor.close();
return audioCursorToArray;
}
public Cursor fetchAudioInListCursor(long j, long j2) {
return this.mDbHelper.getWritableDatabase().rawQuery("SELECT a.audio_id, a.artist, a.title,a.duration, a.url, a.owner_id, a.lyrics_id, a.genre_id FROM audio_in_list as ail JOIN audio as a on a.audio_id=ail.audio_id AND a.owner_id=ail.list_owner_id WHERE ail.list_id=? AND ail.list_owner_id=? ORDER BY ail._id", new String[]{Long.toString(j), Long.toString(j2)});
}
public ArrayList fetchAudiosFromWall(long j) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("select w.attachments from wall as w where w.to_id=? order by w._id", toArg(j));
ArrayList arrayList = new ArrayList();
while (rawQuery.moveToNext()) {
Iterator it = deserializeAttachments(rawQuery.getBlob(0), 0L).iterator();
while (it.hasNext()) {
Attachment attachment = (Attachment) it.next();
if (attachment.type.equals("audio")) {
arrayList.add(attachment.audio);
}
}
}
rawQuery.close();
return arrayList;
}
public ArrayList fetchChatAvatars(long j) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT u.photo_medium_rec FROM chat_members as a LEFT JOIN users as u ON u._id = a.user_id WHERE a.chat_id=? ORDER by a._id LIMIT 4", toArg(j));
ArrayList arrayList = new ArrayList();
while (rawQuery.moveToNext()) {
arrayList.add(rawQuery.getString(0));
}
rawQuery.close();
return arrayList;
}
public ArrayList fetchChatFullMembers(long j) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT u._id, u.first_name, u.last_name, u.photo, u.photo_medium_rec, u.online, u.domain, a.user_id, g.name, g.photo_medium FROM chat_members as a LEFT JOIN users as u ON u._id=a.user_id AND a.user_id>0 LEFT JOIN groups as g ON g._id=a.user_id*(-1) AND a.user_id<0 WHERE a.chat_id=? ORDER by a._id", toArg(j));
ArrayList arrayList = new ArrayList();
while (rawQuery.moveToNext()) {
long j2 = rawQuery.getLong(rawQuery.getColumnIndex("user_id"));
if (j2 > 0) {
User user = new User();
user.uid = rawQuery.getLong(rawQuery.getColumnIndex("_id"));
user.first_name = rawQuery.getString(rawQuery.getColumnIndex("first_name"));
user.last_name = rawQuery.getString(rawQuery.getColumnIndex("last_name"));
user.photo_medium_rec = rawQuery.getString(rawQuery.getColumnIndex("photo_medium_rec"));
user.photo = rawQuery.getString(rawQuery.getColumnIndex("photo"));
user.online = Boolean.valueOf(rawQuery.getLong(rawQuery.getColumnIndex("online")) == 1);
user.domain = rawQuery.getString(rawQuery.getColumnIndex("domain"));
arrayList.add(new ChatMember(user));
} else {
Group group = new Group();
group.gid = j2 * (-1);
group.name = rawQuery.getString(rawQuery.getColumnIndex("name"));
group.photo_medium = rawQuery.getString(rawQuery.getColumnIndex("photo_medium"));
arrayList.add(new ChatMember(group));
}
}
rawQuery.close();
return arrayList;
}
public CharSequence fetchChatName(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("chat", new String[]{"title"}, "chat_id=? AND account_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null);
if (query.getCount() == 0) {
query.close();
return null;
}
query.moveToFirst();
String string = query.getString(0);
query.close();
return string;
}
public String fetchCity(long j) {
Cursor query = this.mDbHelper.getWritableDatabase().query("cities", new String[]{"name"}, "_id=?", toArg(j), null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
String string = query.getString(query.getColumnIndex("name"));
query.close();
return string;
}
public ArrayList fetchCommentList(long j, long j2, long j3, long j4) {
Cursor fetchComments = fetchComments(j, j2, j3, j4);
ArrayList arrayList = new ArrayList();
int columnIndex = fetchComments.getColumnIndex("message");
int columnIndex2 = fetchComments.getColumnIndex("from_id");
int columnIndex3 = fetchComments.getColumnIndex("like_count");
int columnIndex4 = fetchComments.getColumnIndex("like");
int columnIndex5 = fetchComments.getColumnIndex("comment_id");
int columnIndex6 = fetchComments.getColumnIndex("date");
int columnIndex7 = fetchComments.getColumnIndex("reply_to_cid");
int columnIndex8 = fetchComments.getColumnIndex("reply_to_uid");
while (fetchComments.moveToNext()) {
Comment comment = new Comment();
comment.message = fetchComments.getString(columnIndex);
comment.from_id = fetchComments.getLong(columnIndex2);
comment.like_count = fetchComments.getInt(columnIndex3);
comment.user_like = fetchComments.getInt(columnIndex4) == 1;
comment.cid = fetchComments.getLong(columnIndex5);
comment.date = fetchComments.getLong(columnIndex6);
if (!fetchComments.isNull(columnIndex7)) {
comment.reply_to_cid = fetchComments.getLong(columnIndex7);
}
if (!fetchComments.isNull(columnIndex8)) {
comment.reply_to_uid = fetchComments.getLong(columnIndex8);
}
arrayList.add(comment);
}
fetchComments.close();
return arrayList;
}
public Cursor fetchComments(long j, long j2, long j3, long j4) {
return this.mDbHelper.getWritableDatabase().rawQuery("SELECT c._id as _id, c.comment_id as comment_id, c.date as date, c.message as message, c.from_id as from_id, c.content_id, c.like_count as like_count, wl.[like] as [like], c.reply_to_cid, c.reply_to_uid FROM comments as c LEFT JOIN wall_like as wl on wl.post_id=c.comment_id AND wl.wall_owner_id=? AND wl.account_id=? AND wl.type=? WHERE c.content_id=? AND c.content_type=? AND c.content_owner_id=? ORDER BY c.date", new String[]{Long.toString(j3), Long.toString(j4), Integer.toString(contentTypeToLikeType(j2)), Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public String fetchCountry(long j) {
Cursor query = this.mDbHelper.getWritableDatabase().query("countries", new String[]{"name"}, "_id=?", toArg(j), null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
String string = query.getString(query.getColumnIndex("name"));
query.close();
return string;
}
public Cursor fetchDialogs(long j, long j2, Collection collection, Collection collection2, boolean z) {
String str;
String str2;
String str3;
if (collection == null || collection.size() == 0) {
str = "";
} else {
str = " AND chat_id not in (" + TextUtils.join(",", collection) + ") ";
}
if (collection2 == null || collection2.size() == 0) {
str2 = "";
str3 = str2;
} else {
str2 = " ,case when ch.chat_id in(" + TextUtils.join(",", collection2) + ") then 1 else 0 end as fixed ";
str3 = "fixed DESC,";
}
StringBuilder sb = new StringBuilder();
sb.append("select m2._id as _id, m2.message_id as message_id, m2.date as date, m2.uid as uid, m2.title as title, m2.body as body, m2.is_out as is_out, m2.read_state as read_state, m2.have_attachments as have_attachments, m2.[action] as [action], m2.action_mid as action_mid, m2.action_text as action_text, substr(m2.attachments,1,2087152) as attachments, u.photo_medium_rec as photo_medium_rec, u.first_name as first_name, u.last_name as last_name, u.online as online, u.online_mobile as online_mobile, ch.chat_id as chat_id, ch.title as chat_title, ch.photo_100 as chat_photo_100, ch.unread_count as unread_count ");
sb.append(str2);
sb.append("FROM chat as ch INNER JOIN (SELECT max(m.message_id) as max_message_id, m.chat_id as x_chat_id FROM messages as m WHERE m.account_id=? and m.group_id=?AND m.chat_id in (SELECT DISTINCT chat_id from chat WHERE account_id=? ");
sb.append(str);
sb.append(" ) GROUP BY m.chat_id) on ch.chat_id=x_chat_id LEFT JOIN messages as m2 on m2.message_id=max_message_id AND m2.account_id=? AND m2.group_id=?LEFT JOIN users as u on m2.uid=u._id WHERE ch.account_id=? AND ch.group_id=? ");
sb.append(z ? "AND m2.read_state=0 AND m2.is_out=0 " : "");
sb.append("ORDER BY ");
sb.append(str3);
sb.append("m2.message_id DESC");
return this.mDbHelper.getWritableDatabase().rawQuery(sb.toString(), new String[]{Long.toString(j), Long.toString(j2), Long.toString(j), Long.toString(j), Long.toString(j2), Long.toString(j), Long.toString(j2)});
}
public Document fetchDoc(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("docs", new String[]{"title"}, "doc_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Document document = new Document();
document.id = j;
document.title = query.getString(0);
query.close();
return document;
}
public Document fetchDocFull(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("docs", new String[]{"title", "owner_id", "size", "url", "thumb", "ext", "thumb_s"}, "doc_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Document document = new Document();
document.id = j;
document.title = query.getString(0);
document.owner_id = query.getLong(1);
document.size = query.getLong(2);
document.url = query.getString(3);
document.thumb = query.getString(4);
document.ext = query.getString(5);
document.thumb_o = query.getString(6);
query.close();
return document;
}
public Cursor fetchDocs(long j, String str) {
String[] arg = toArg(j);
String str2 = "SELECT ds._id as _id, ds.doc_id as doc_id, ds.title as title, ds.size as size, ds.url as url, ds.thumb as thumb, ds.ext as ext FROM docs as ds WHERE ds.owner_id=?";
if (str != null && !str.equals("")) {
str2 = "SELECT ds._id as _id, ds.doc_id as doc_id, ds.title as title, ds.size as size, ds.url as url, ds.thumb as thumb, ds.ext as ext FROM docs as ds WHERE ds.owner_id=? AND ds.title_lower LIKE ?";
arg = new String[]{Long.toString(j), "%" + str.toLowerCase().trim() + "%"};
}
return this.mDbHelper.getWritableDatabase().rawQuery(str2 + " order by ds.doc_id DESC", arg);
}
public Cursor fetchFaveGroups(long j, String str) {
ArrayList arrayList = new ArrayList();
arrayList.add(Long.toString(j));
String str2 = "select g._id as _id, g.name as name, g.photo_medium as photo_medium, g.type as type, g.is_closed as is_closed from fave_groups as fg left join groups as g on g._id=fg.group_id where fg.account_id=?";
if (!TextUtils.isEmpty(str)) {
str2 = "select g._id as _id, g.name as name, g.photo_medium as photo_medium, g.type as type, g.is_closed as is_closed from fave_groups as fg left join groups as g on g._id=fg.group_id where fg.account_id=? AND g.name_lower LIKE ? ";
arrayList.add("%" + str.toLowerCase().trim() + "%");
}
return this.mDbHelper.getWritableDatabase().rawQuery(str2, (String[]) arrayList.toArray(new String[0]));
}
public Cursor fetchFaveLinks(long j) {
return this.mDbHelper.getWritableDatabase().rawQuery("select fl._id as _id, fl.url as url, fl.title as title, fl.description as description, fl.image_src as image_src, fl.link_id as link_id from fave_links as fl where fl.account_id=?", toArg(j));
}
public Cursor fetchFavePosts(long j, boolean z) {
return this.mDbHelper.getWritableDatabase().rawQuery("select w._id as _id, w.post_id as post_id, w.date as date, w.from_id as from_id, w.text as text, w.to_id as to_id, w.likes_count as likes_count, wl.[like] as [like], wl.reposted as reposted, w.reposts_count as reposts_count, w.comments_count as comments_count, w.copy_owner_id as copy_owner_id, w.copy_text as copy_text, w.signer_id as signer_id, w.views as views, w.copyright_name as copyright_name, g.photo_medium as photo_medium, g.name as name, w.attachments as attachments, u.first_name as first_name, u.last_name as last_name, u.photo_medium_rec as photo_medium_rec from fave_posts as fp left join wall as w INDEXED BY index_wall_1 on fp.post_id=w.post_id AND w.to_id=fp.owner_id left join users as u on w.from_id=u._id left join groups as g on -w.from_id=g._id left join wall_like as wl on wl.wall_owner_id=fp.owner_id AND wl.post_id=fp.post_id AND wl.account_id=? AND wl.type=0 where fp.account_id=? order by fp._id", new String[]{Long.toString(j), Long.toString(z ? -j : j)});
}
public Cursor fetchFaveUsers(long j, String str) {
ArrayList arrayList = new ArrayList();
arrayList.add(Long.toString(j));
String str2 = "select u._id as _id, u.first_name as first_name, u.last_name as last_name, u.photo_medium_rec as photo_medium_rec, u.online as online, u.online_mobile as online_mobile from fave_users as fu left join users as u on u._id=fu.user_id where fu.account_id=?";
if (str != null && !str.equals("")) {
String trim = str.toLowerCase().trim();
String transform = TranslitTransformer.transform(trim);
str2 = "select u._id as _id, u.first_name as first_name, u.last_name as last_name, u.photo_medium_rec as photo_medium_rec, u.online as online, u.online_mobile as online_mobile from fave_users as fu left join users as u on u._id=fu.user_id where fu.account_id=? AND (u.first_name_lower LIKE ? OR u.last_name_lower LIKE ? OR u.nickname_lower LIKE ? OR u.first_name_lower LIKE ? OR u.last_name_lower LIKE ? OR u.nickname_lower LIKE ?)";
String str3 = "%" + trim + "%";
String str4 = "%" + transform + "%";
arrayList.add(str3);
arrayList.add(str3);
arrayList.add(str3);
arrayList.add(str4);
arrayList.add(str4);
arrayList.add(str4);
}
String[] strArr = new String[arrayList.size()];
arrayList.toArray(strArr);
return this.mDbHelper.getWritableDatabase().rawQuery(str2, strArr);
}
public Cursor fetchFriendBirthdays(long j) {
return this.mDbHelper.getWritableDatabase().rawQuery("select u._id, u.birthdate, u.first_name, u.last_name, u.photo_medium_rec, u.online from users as u join friends as f on u._id=f.friend_id where u.birthdate<>'' and f.owner_id=?", toArg(j));
}
public Cursor fetchFriendCities(long j) {
return this.mDbHelper.getWritableDatabase().rawQuery("select u.city, count(*) as x, c.name from friends as f join users as u on u._id=f.friend_id left join cities as c on u.city=c._id where f.owner_id=? AND u.city not null AND u.city!=0 GROUP BY u.city ORDER BY x DESC", toArg(j));
}
public Cursor fetchFriends(long j, String str, boolean z) {
return fetchFriends(j, str, z, 0, 0L);
}
public Cursor fetchFriends(long j, String str, boolean z, int i, long j2) {
ArrayList arrayList = new ArrayList();
arrayList.add(Long.toString(j));
String str2 = "select u._id, u.first_name, u.last_name, u.photo_medium_rec, u.online, u.online_mobile from friends as f LEFT join users as u on u._id=f.friend_id where f.owner_id=? ";
if (str != null && !str.equals("")) {
String trim = str.toLowerCase().trim();
String transform = TranslitTransformer.transform(trim);
str2 = "select u._id, u.first_name, u.last_name, u.photo_medium_rec, u.online, u.online_mobile from friends as f LEFT join users as u on u._id=f.friend_id where f.owner_id=? AND (u.first_name_lower LIKE ? OR u.last_name_lower LIKE ? OR u.nickname_lower LIKE ? OR u.first_name_lower LIKE ? OR u.last_name_lower LIKE ? OR u.nickname_lower LIKE ?)";
String str3 = "%" + trim + "%";
String str4 = "%" + transform + "%";
arrayList.add(str3);
arrayList.add(str3);
arrayList.add(str3);
arrayList.add(str4);
arrayList.add(str4);
arrayList.add(str4);
}
if (i != 0) {
str2 = str2 + " and u.sex =?";
arrayList.add(Integer.toString(i));
}
if (j2 != 0) {
str2 = str2 + " and u.city =?";
arrayList.add(Long.toString(j2));
}
String[] strArr = new String[arrayList.size()];
arrayList.toArray(strArr);
if (z) {
str2 = str2 + "ORDER BY online DESC, f._id";
}
return this.mDbHelper.getWritableDatabase().rawQuery(str2, strArr);
}
public Group fetchGroup(long j) {
Cursor query = this.mDbHelper.getWritableDatabase().query("groups", new String[]{"name", "photo_medium"}, "_id= ?", toArg(j), null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Group group = new Group();
group.gid = j;
group.name = query.getString(0);
group.photo_medium = query.getString(1);
query.close();
return group;
}
public Group fetchGroupFull(long j) {
Cursor query = this.mDbHelper.getWritableDatabase().query("groups", new String[]{"name", "photo_medium", "is_closed", "description", "wiki", "fixed_post", "can_see_all_posts", "members_count", "type", "start_date", "photo_big", "status", "photos", "albums", "topics", "videos", "audios", "docs", "posts", "verified", "can_message", "market_enabled", "market_wiki_id", "market_wiki_title", "market_contact_id", "cover_400", "cover_800", "podcasts"}, "_id= ?", toArg(j), null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Group group = new Group();
group.gid = j;
group.name = query.getString(0);
group.photo_medium = query.getString(1);
group.is_closed = Integer.valueOf(query.getInt(2));
group.description = query.getString(3);
group.wiki_page = query.getString(4);
if (!query.isNull(5)) {
group.fixed_post = Long.valueOf(query.getLong(5));
}
group.can_see_all_posts = Boolean.valueOf(query.getLong(6) == 1);
if (!query.isNull(7)) {
group.members_count = Integer.valueOf(query.getInt(7));
}
if (!query.isNull(8)) {
group.type = Integer.valueOf(query.getInt(8));
}
if (!query.isNull(9)) {
group.start_date = Long.valueOf(query.getLong(9));
}
if (!query.isNull(10)) {
group.photo_big = query.getString(10);
}
if (!query.isNull(11)) {
group.status = query.getString(11);
}
if (!query.isNull(12)) {
group.photos_count = Integer.valueOf(query.getInt(12));
}
if (!query.isNull(13)) {
group.albums_count = Integer.valueOf(query.getInt(13));
}
if (!query.isNull(14)) {
group.topics_count = Integer.valueOf(query.getInt(14));
}
if (!query.isNull(15)) {
group.videos_count = Integer.valueOf(query.getInt(15));
}
if (!query.isNull(16)) {
group.audios_count = Integer.valueOf(query.getInt(16));
}
if (!query.isNull(17)) {
group.docs_count = Integer.valueOf(query.getInt(17));
}
if (!query.isNull(18)) {
group.posts_count = Integer.valueOf(query.getInt(18));
}
if (!query.isNull(19)) {
group.verified = Integer.valueOf(query.getInt(19));
}
if (!query.isNull(20)) {
group.can_message = Boolean.valueOf(query.getInt(20) == 1);
}
if (!query.isNull(21)) {
group.market_enabled = Boolean.valueOf(query.getInt(21) == 1);
}
if (!query.isNull(22)) {
Page page = new Page();
group.market_wiki = page;
page.id = query.getLong(22);
group.market_wiki.title = query.getString(23);
}
if (!query.isNull(24)) {
group.market_contact_id = Long.valueOf(query.getLong(24));
}
if (!query.isNull(25)) {
group.cover_400 = query.getString(25);
}
if (!query.isNull(26)) {
group.cover_800 = query.getString(26);
}
if (!query.isNull(27)) {
group.podcasts_count = Integer.valueOf(query.getInt(27));
}
query.close();
return group;
}
public Cursor fetchGroupTopics(long j, String str) {
String[] strArr;
String str2;
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
String[] arg = toArg(j);
if (TextUtils.isEmpty(str)) {
strArr = arg;
str2 = "group_id=?";
} else {
str2 = "group_id=? AND title_lower LIKE ? ";
strArr = new String[]{Long.toString(j), "%" + str.toLowerCase() + "%"};
}
return writableDatabase.query("group_topics", new String[]{"_id", "group_id", "title", "comments", "created", "created_by", "updated", "updated_by", "is_closed", "is_fixed"}, str2, strArr, null, null, "is_fixed DESC,updated DESC");
}
public ArrayList fetchGroups(ArrayList arrayList) {
if (arrayList.size() == 0) {
return null;
}
Iterator it = arrayList.iterator();
String str = "";
while (it.hasNext()) {
Long l = (Long) it.next();
if (!str.equals("")) {
str = str + ",";
}
str = str + l;
}
Cursor query = this.mDbHelper.getWritableDatabase().query("groups", new String[]{"_id"}, "_id IN (" + str + ")", null, null, null, null);
if (query == null) {
return null;
}
ArrayList arrayList2 = new ArrayList();
while (query.moveToNext()) {
arrayList2.add(Long.valueOf(query.getLong(0)));
}
query.close();
return arrayList2;
}
public long fetchLatestDialog(long j, long j2) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT chat_id FROM messages WHERE account_id=? AND group_id=? ORDER BY date DESC limit 0,1", new String[]{Long.toString(j), Long.toString(j2)});
if (rawQuery.getCount() == 0) {
rawQuery.close();
return 0L;
}
rawQuery.moveToFirst();
long j3 = rawQuery.getLong(0);
rawQuery.close();
return j3;
}
public ArrayList fetchManagedGroups(long j, Long l) {
ArrayList arrayList = new ArrayList();
Cursor cursor = null;
try {
cursor = KApplication.db.fetchUserGroups(j, null, null, true, true, false, l);
if (cursor != null) {
while (cursor.moveToNext()) {
Group group = new Group();
group.gid = cursor.getLong(cursor.getColumnIndex("_id"));
group.name = cursor.getString(cursor.getColumnIndex("name"));
arrayList.add(group);
}
}
return arrayList;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
public Message fetchMessage(long j, long j2, long j3) {
Cursor cursor = null;
try {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT m.date, m.uid, m.body, m.is_out, m.attachments FROM messages as m WHERE m.message_id=? AND m.account_id=? AND m.group_id=?", new String[]{Long.toString(j2), Long.toString(j), Long.toString(j3)});
if (rawQuery != null) {
try {
if (rawQuery.getCount() != 0) {
rawQuery.moveToFirst();
Message message = new Message();
message.mid = j2;
message.date = rawQuery.getLong(0);
message.uid = rawQuery.getLong(1);
message.body = rawQuery.getString(2);
message.is_out = rawQuery.getLong(3) == 1;
message.attachments = deserializeAttachments(rawQuery.getBlob(4), j);
rawQuery.close();
return message;
}
} catch (Throwable th) {
th = th;
cursor = rawQuery;
if (cursor != null) {
cursor.close();
}
throw th;
}
}
if (rawQuery != null) {
rawQuery.close();
}
return null;
} catch (Throwable th2) {
th = th2;
}
}
public Cursor fetchMessagesThread(long j, long j2, long j3, boolean z, long j4) {
String[] strArr = {Long.toString(ThreadIdHelper.makeThreadId(Long.valueOf(j2), Long.valueOf(j))), Long.toString(j3), Long.toString(j4)};
String str = "SELECT m.message_id, m.date, m.uid, m.title, m.body, m.is_out, m.read_state, m.have_attachments, m.important, m.action, m.action_mid, m.action_text, m.update_time, substr(m.attachments, 1, 2087152) as attachments FROM messages as m WHERE m.chat_id=? AND m.account_id=? AND m.group_id=?ORDER BY m.message_id";
if (!z) {
str = str + " DESC";
}
return this.mDbHelper.getWritableDatabase().rawQuery(str, strArr);
}
public Note fetchNote(long j) {
Cursor query = this.mDbHelper.getWritableDatabase().query("notes", new String[]{"_id", "date", "from_id", "text", "title"}, "_id=?", toArg(j), null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Note note = new Note();
note.nid = j;
note.date = query.getLong(query.getColumnIndex("date"));
note.owner_id = query.getLong(query.getColumnIndex("from_id"));
note.text = query.getString(query.getColumnIndex("text"));
note.title = query.getString(query.getColumnIndex("title"));
query.close();
return note;
}
public Cursor fetchNotes(long j) {
return this.mDbHelper.getWritableDatabase().query("notes", new String[]{"_id", "date", "from_id", "text", "title", "comments"}, "from_id=?", toArg(j), null, null, "date DESC");
}
public Cursor fetchOnlineFriends(long j) {
return this.mDbHelper.getWritableDatabase().rawQuery("select u._id, u.first_name, u.last_name, u.photo_medium_rec, u.online, u.online_mobile from users as u join friends as f on u._id=f.friend_id where f.owner_id=? AND u.online=1", toArg(j));
}
public Photo fetchPhoto(long j, long j2, long j3) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT p.photo_id, p.src, p.src_big, p.src_xbig, p.src_xxbig, p.src_xxxbig, p.owner_id, p.phototext, p.album_id, wl.[like] as [like], p.like_count as like_count, p.comments_count as comments_count ,p.lat as lat, p.lon as lon FROM photos as p LEFT JOIN wall_like as wl on wl.post_id=p.photo_id AND wl.wall_owner_id=p.owner_id AND wl.account_id=? AND wl.type=1 WHERE p.photo_id=? AND p.owner_id=? LIMIT 1", new String[]{Long.toString(j3), Long.toString(j), Long.toString(j2)});
if (rawQuery == null) {
return null;
}
if (rawQuery.getCount() == 0) {
rawQuery.close();
return null;
}
return (Photo) getPhotos(rawQuery).get(0);
}
public Photo fetchPhotoFull(long j, long j2) {
Cursor cursor = null;
try {
Cursor query = this.mDbHelper.getWritableDatabase().query("photos", new String[]{"src", "src_big", "phototext", "album_id", "created", "width", "height"}, "photo_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
if (query != null) {
query.close();
}
return null;
}
try {
if (query.getCount() == 0) {
query.close();
return null;
}
query.moveToFirst();
Photo photo = new Photo();
photo.pid = j;
photo.src = query.getString(0);
photo.src_big = query.getString(1);
photo.owner_id = Long.toString(j2);
photo.phototext = query.getString(2);
photo.aid = query.getLong(3);
photo.created = query.getLong(4);
photo.width = query.getInt(5);
photo.height = query.getInt(6);
query.close();
return photo;
} catch (Throwable th) {
th = th;
cursor = query;
if (cursor != null) {
cursor.close();
}
throw th;
}
} catch (Throwable th2) {
th = th2;
}
}
public Cursor fetchPhotos(long j, long j2, long j3) {
return fetchPhotos(j, j2, j3, false);
}
public Cursor fetchPhotos(long j, long j2, long j3, boolean z) {
String str = "SELECT p.photo_id, p.src, p.src_big, p.src_xbig, p.src_xxbig, p.src_xxxbig, p.owner_id, p.phototext, p.album_id, wl.[like] as [like], p.like_count as like_count, p.comments_count as comments_count ,p.lat as lat, p.lon as lon FROM albumphoto as ap INDEXED BY index_albumphoto_1 JOIN photos as p INDEXED BY index_photo_1 on p.photo_id=ap.photo_id AND p.owner_id=ap.photo_owner_id LEFT JOIN wall_like as wl on wl.post_id=p.photo_id AND wl.wall_owner_id=p.owner_id AND wl.account_id=? AND wl.type=1 WHERE ap.album_id=? AND ap.album_owner_id=? ORDER BY ap._id";
if (z) {
str = "explain query plan SELECT p.photo_id, p.src, p.src_big, p.src_xbig, p.src_xxbig, p.src_xxxbig, p.owner_id, p.phototext, p.album_id, wl.[like] as [like], p.like_count as like_count, p.comments_count as comments_count ,p.lat as lat, p.lon as lon FROM albumphoto as ap INDEXED BY index_albumphoto_1 JOIN photos as p INDEXED BY index_photo_1 on p.photo_id=ap.photo_id AND p.owner_id=ap.photo_owner_id LEFT JOIN wall_like as wl on wl.post_id=p.photo_id AND wl.wall_owner_id=p.owner_id AND wl.account_id=? AND wl.type=1 WHERE ap.album_id=? AND ap.album_owner_id=? ORDER BY ap._id";
}
return this.mDbHelper.getWritableDatabase().rawQuery(str, new String[]{Long.toString(j3), Long.toString(j), Long.toString(j2)});
}
public VkPoll fetchPoll(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("poll", null, "poll_id=? AND account_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
VkPoll vkPoll = new VkPoll();
vkPoll.id = j;
vkPoll.question = query.getString(query.getColumnIndex("question"));
vkPoll.owner_id = query.getLong(query.getColumnIndex("owner_id"));
vkPoll.votes = Long.valueOf(query.getLong(query.getColumnIndex("votes")));
vkPoll.answers_json = query.getString(query.getColumnIndex("answers"));
vkPoll.anonymous = 1 == query.getLong(query.getColumnIndex("anonymous"));
query.close();
return vkPoll;
}
public Cursor fetchPostNews(long j, int i) {
return this.mDbHelper.getWritableDatabase().rawQuery("SELECT n._id as _id, n.type as type, n.post_id as post_id, n.source_id as source_id, n.text as text, n.date as date, n.comment_count as comment_count, n.comment_can_post as comment_can_post, n.like_count as like_count, n.user_like as user_like, n.from_id as from_id, n.comments as comments_json, n.is_comments as is_comments, n.reposts_count as reposts_count, n.copy_owner_id as copy_owner_id, n.copy_text as copy_text, n.signer_id as signer_id, n.views as views, n.user_reposted as user_reposted, n.attachments as attachments, n.copyright_name as copyright_name, u.first_name as first_name, u.last_name as last_name, u.photo as photo, u.photo_big as photo_big, u.online as online, g.photo_medium as photo_medium, g.name as name, n.ads_title as ads_title, n.age_restriction as age_restriction, n.ad_data as ad_data, n.ad_data_impression as ad_data_impression, n.statistics as statistics, n.track_code as track_code, n.ads_id1 as ads_id1, n.ads_id2 as ads_id2, n.advertiser_info_url as advertiser_info_url FROM news as n left join users as u on n.source_id=u._id left join groups as g on -n.source_id=g._id where n.account_id=? AND n.is_comments=? order by n._id", new String[]{Long.toString(j), Integer.toString(i)});
}
public Cursor fetchTopFriends(long j, String str) {
String[] arg = toArg(j);
String str2 = "select u._id, u.first_name, u.last_name, u.photo_medium_rec, u.online from users as u join friends as f on u._id=f.friend_id where f.owner_id=?";
if (str != null && !str.equals("")) {
String str3 = "%" + str.toLowerCase().trim() + "%";
String[] strArr = {Long.toString(j), str3, str3, str3};
String str4 = ("select u._id, u.first_name, u.last_name, u.photo_medium_rec, u.online from users as u join friends as f on u._id=f.friend_id where f.owner_id=? AND (u.first_name_lower LIKE ? OR u.last_name_lower LIKE ? OR u.nickname_lower LIKE ?) ") + "ORDER BY online DESC, f._id";
arg = strArr;
str2 = str4 + " LIMIT 0,20";
}
return this.mDbHelper.getWritableDatabase().rawQuery(str2, arg);
}
public String fetchTopicTitle(long j) {
Cursor query = this.mDbHelper.getWritableDatabase().query("group_topics", new String[]{"title"}, "_id=?", new String[]{Long.toString(j)}, null, null, null);
if (query.getCount() == 0) {
return null;
}
query.moveToFirst();
String string = query.getString(0);
query.close();
return string;
}
public User fetchUser(long j) {
Cursor query = this.mDbHelper.getWritableDatabase().query("users", new String[]{"_id", "first_name", "last_name", "photo_medium_rec", "photo", "online", "online_mobile"}, "_id= ?", toArg(j), null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
User user = new User();
user.uid = j;
user.first_name = query.getString(query.getColumnIndex("first_name"));
user.last_name = query.getString(query.getColumnIndex("last_name"));
user.photo_medium_rec = query.getString(query.getColumnIndex("photo_medium_rec"));
user.photo = query.getString(query.getColumnIndex("photo"));
user.online = Boolean.valueOf(query.getLong(query.getColumnIndex("online")) == 1);
user.online_mobile = Boolean.valueOf(query.getLong(query.getColumnIndex("online_mobile")) == 1);
query.close();
return user;
}
public User fetchUserByDomain(String str) {
Cursor query = this.mDbHelper.getWritableDatabase().query("users", new String[]{"_id", "first_name", "last_name", "photo_medium_rec", "photo", "online", "domain"}, "domain= ?", new String[]{str}, null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
User user = new User();
user.uid = query.getLong(query.getColumnIndex("_id"));
user.first_name = query.getString(query.getColumnIndex("first_name"));
user.last_name = query.getString(query.getColumnIndex("last_name"));
user.photo_medium_rec = query.getString(query.getColumnIndex("photo_medium_rec"));
user.photo = query.getString(query.getColumnIndex("photo"));
user.online = Boolean.valueOf(query.getLong(query.getColumnIndex("online")) == 1);
user.domain = query.getString(query.getColumnIndex("domain"));
query.close();
return user;
}
public User fetchUserFull(long j) {
Cursor cursor = null;
try {
Cursor query = this.mDbHelper.getWritableDatabase().query("users", new String[]{"_id", "first_name", "last_name", "photo_medium_rec", "nickname", "photo", "photo_big", "photo_200", "domain", "sex", "birthdate", "city", "country", "rate", "mobile_phone", "home_phone", "university", "university_name", "faculty", "faculty_name", "graduation", "online", "online_mobile", "status", "relation", "last_seen", "albums", "photos", "audios", "videos", "notes", "friends", "online_friends", "user_photos", "groups", "followers", "gifts", "posts", "photo_400_orig", "verified", "mutual_friends", "cover_400", "cover_960", "crop_photo_rect_x1", "crop_photo_rect_x2", "crop_photo_rect_y1", "crop_photo_rect_y2"}, "_id= ?", toArg(j), null, null, null, "1");
if (query == null) {
if (query != null) {
query.close();
}
return null;
}
try {
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
User user = new User();
user.uid = j;
user.first_name = query.getString(query.getColumnIndex("first_name"));
user.last_name = query.getString(query.getColumnIndex("last_name"));
user.nickname = query.getString(query.getColumnIndex("nickname"));
user.photo = query.getString(query.getColumnIndex("photo"));
user.photo_medium_rec = query.getString(query.getColumnIndex("photo_medium_rec"));
user.photo_big = query.getString(query.getColumnIndex("photo_big"));
user.photo_200 = query.getString(query.getColumnIndex("photo_200"));
user.photo_400_orig = query.getString(query.getColumnIndex("photo_400_orig"));
user.domain = query.getString(query.getColumnIndex("domain"));
if (!query.isNull(query.getColumnIndex("sex"))) {
user.sex = Integer.valueOf(query.getInt(query.getColumnIndex("sex")));
}
user.birthdate = query.getString(query.getColumnIndex("birthdate"));
user.city = Integer.valueOf(query.getInt(query.getColumnIndex("city")));
user.country = Integer.valueOf(query.getInt(query.getColumnIndex("country")));
user.rate = Integer.valueOf(query.getInt(query.getColumnIndex("rate")));
user.mobile_phone = query.getString(query.getColumnIndex("mobile_phone"));
user.home_phone = query.getString(query.getColumnIndex("home_phone"));
user.university = Integer.valueOf(query.getInt(query.getColumnIndex("university")));
user.university_name = query.getString(query.getColumnIndex("university_name"));
user.faculty = Integer.valueOf(query.getInt(query.getColumnIndex("faculty")));
user.faculty_name = query.getString(query.getColumnIndex("faculty_name"));
user.graduation = Integer.valueOf(query.getInt(query.getColumnIndex("graduation")));
user.online = Boolean.valueOf(query.getInt(query.getColumnIndex("online")) == 1);
user.online_mobile = Boolean.valueOf(query.getInt(query.getColumnIndex("online_mobile")) == 1);
user.status = query.getString(query.getColumnIndex("status"));
user.relation = Integer.valueOf(query.getInt(query.getColumnIndex("relation")));
user.last_seen = query.getLong(query.getColumnIndex("last_seen"));
user.albums_count = query.getInt(query.getColumnIndex("albums"));
user.photo_count = query.getInt(query.getColumnIndex("photos"));
user.videos_count = query.getInt(query.getColumnIndex("videos"));
user.audios_count = query.getInt(query.getColumnIndex("audios"));
user.notes_count = query.getInt(query.getColumnIndex("notes"));
user.friends_count = query.getInt(query.getColumnIndex("friends"));
if (!query.isNull(query.getColumnIndex("online_friends"))) {
user.online_friends_count = Integer.valueOf(query.getInt(query.getColumnIndex("online_friends")));
}
user.user_photos_count = query.getInt(query.getColumnIndex("user_photos"));
user.groups_count = query.getInt(query.getColumnIndex("groups"));
user.followers_count = query.getInt(query.getColumnIndex("followers"));
if (!query.isNull(query.getColumnIndex("gifts"))) {
user.gifts_count = query.getInt(query.getColumnIndex("gifts"));
}
if (!query.isNull(query.getColumnIndex("posts"))) {
user.posts_count = Integer.valueOf(query.getInt(query.getColumnIndex("posts")));
}
if (!query.isNull(query.getColumnIndex("verified"))) {
user.verified = Integer.valueOf(query.getInt(query.getColumnIndex("verified")));
}
if (!query.isNull(query.getColumnIndex("mutual_friends"))) {
user.mutual_friends_count = Integer.valueOf(query.getInt(query.getColumnIndex("mutual_friends")));
}
User.Rect rect = new User.Rect();
if (!query.isNull(query.getColumnIndex("crop_photo_rect_x1"))) {
rect.x1 = query.getDouble(query.getColumnIndex("crop_photo_rect_x1"));
}
if (!query.isNull(query.getColumnIndex("crop_photo_rect_x2"))) {
rect.x2 = query.getDouble(query.getColumnIndex("crop_photo_rect_x2"));
}
if (!query.isNull(query.getColumnIndex("crop_photo_rect_y1"))) {
rect.y1 = query.getDouble(query.getColumnIndex("crop_photo_rect_y1"));
}
if (!query.isNull(query.getColumnIndex("crop_photo_rect_y2"))) {
rect.y2 = query.getDouble(query.getColumnIndex("crop_photo_rect_y2"));
}
if (rect.x1 != 0.0d || rect.x2 != 0.0d || rect.y1 != 0.0d || rect.y2 != 0.0d) {
user.crop_photo_rect = rect;
}
int columnIndex = query.getColumnIndex("cover_400");
if (!query.isNull(columnIndex)) {
user.cover_400 = query.getString(columnIndex);
}
int columnIndex2 = query.getColumnIndex("cover_960");
if (!query.isNull(columnIndex2)) {
user.cover_960 = query.getString(columnIndex2);
}
query.close();
return user;
} catch (Throwable th) {
th = th;
cursor = query;
if (cursor != null) {
cursor.close();
}
throw th;
}
} catch (Throwable th2) {
th = th2;
}
}
public Cursor fetchUserGroups(long j, Integer num, String str, boolean z, boolean z2, boolean z3, Long l) {
String[] arg = toArg(j);
String str2 = "select g._id as _id, g.name as name, g.photo_medium as photo_medium, g.type as type, g.is_closed as is_closed, g.start_date as start_date from user_group as ug join groups as g on g._id=ug.group_id where ug.user_id=?";
if (str != null && !str.equals("")) {
String trim = str.toLowerCase().trim();
String transform = TranslitTransformer.transform(trim);
str2 = "select g._id as _id, g.name as name, g.photo_medium as photo_medium, g.type as type, g.is_closed as is_closed, g.start_date as start_date from user_group as ug join groups as g on g._id=ug.group_id where ug.user_id=? AND (g.name_lower LIKE ? OR g.name_lower LIKE ?) ";
arg = new String[]{Long.toString(j), "%" + trim + "%", "%" + transform + "%"};
}
if (num != null) {
str2 = str2 + " AND g.type=" + num + " ";
}
if (z) {
str2 = str2 + " AND (ug.admin_level=2 OR ug.admin_level=3) ";
} else if (z2) {
str2 = str2 + " AND (ug.admin_level=1 OR ug.admin_level=2 OR ug.admin_level=3) ";
}
if (l != null) {
str2 = str2 + " AND g.members_count>=" + l + " ";
}
if (z3) {
str2 = str2 + " ORDER BY g.start_date ";
}
return this.mDbHelper.getWritableDatabase().rawQuery(str2, arg);
}
public ArrayList fetchUsers(ArrayList arrayList) {
if (arrayList.size() == 0) {
return null;
}
Iterator it = arrayList.iterator();
String str = "";
while (it.hasNext()) {
Long l = (Long) it.next();
if (!str.equals("")) {
str = str + ",";
}
str = str + l;
}
Cursor query = this.mDbHelper.getWritableDatabase().query("users", new String[]{"_id"}, "_id IN (" + str + ") AND photo_medium_rec is not NULL", null, null, null, null);
if (query == null) {
return null;
}
ArrayList arrayList2 = new ArrayList();
while (query.moveToNext()) {
arrayList2.add(Long.valueOf(query.getLong(0)));
}
query.close();
return arrayList2;
}
public Video fetchVideo(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("video", new String[]{"title", "owner_id", "link", "player_url", "duration", "image", "image_big", "platform"}, "video_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Video video = new Video();
video.vid = j;
video.title = query.getString(0);
video.owner_id = query.getLong(1);
video.player = query.getString(3);
video.duration = query.getLong(4);
video.image = query.getString(5);
video.image_big = query.getString(6);
video.platform = query.getString(7);
query.close();
return video;
}
public Video fetchVideoDescription(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("video", new String[]{"title", "owner_id", "description", "date"}, "video_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Video video = new Video();
video.vid = j;
video.title = query.getString(0);
video.owner_id = query.getLong(1);
video.description = query.getString(2);
video.date = query.getLong(3);
query.close();
return video;
}
public ArrayList fetchVideos(long j, long j2, long j3) {
Cursor cursor = null;
try {
cursor = this.mDbHelper.getWritableDatabase().rawQuery("SELECT v._id as _id, v.video_id as video_id, v.owner_id as owner_id, v.title as title, v.description as description, v.duration as duration, v.platform as platform, v.link as link, v.image as image, v.image_big as image_big, v.player_url as player_url, v.views as views, v.likes_count as likes_count, wl.[like] as [like] FROM video_in_album as va JOIN video as v on v.video_id=va.video_id AND v.owner_id=va.video_owner_id LEFT JOIN wall_like as wl on wl.post_id=v.video_id AND wl.wall_owner_id=v.owner_id AND wl.account_id=? AND wl.type=6 WHERE va.album_owner_id=? AND va.album_id=? ORDER BY va._id", new String[]{Long.toString(j2), Long.toString(j), Long.toString(j3)});
return cursorToVideoArray(cursor);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
public Long fetchWallPost(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("wall", new String[]{"_id"}, "post_id=? AND to_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
return null;
}
query.moveToFirst();
if (query.getCount() == 0) {
query.close();
return null;
}
Long valueOf = Long.valueOf(query.getLong(0));
query.close();
return valueOf;
}
public WallMessage fetchWallPostFromNews(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("news", new String[]{"text", "source_id", "copy_owner_id", "copy_text", "date", "comment_count", "like_count", "signer_id", "post_id", "user_like", "reposts_count", "user_reposted", "comment_can_post", "views", "statistics", "ad_data", "track_code", "attachments", "copyright_link", "copyright_name"}, "_id=?", toArg(j), null, null, null, "1");
if (query.getCount() == 0) {
query.close();
return null;
}
query.moveToFirst();
WallMessage wallMessage = new WallMessage();
wallMessage.id = query.getLong(8);
wallMessage.to_id = query.getLong(1);
wallMessage.text = query.getString(0);
wallMessage.from_id = query.getLong(1);
wallMessage.copy_owner_id = query.getLong(2);
wallMessage.copy_text = query.getString(3);
wallMessage.date = query.getLong(4);
wallMessage.comment_count = query.getLong(5);
wallMessage.like_count = query.getInt(6);
wallMessage.signer_id = query.getLong(7);
wallMessage.user_like = query.getLong(9) == 1;
wallMessage.reposts_count = query.getInt(10);
wallMessage.user_reposted = query.getInt(11) == 1;
wallMessage.comment_can_post = query.getInt(12) == 1;
if (!query.isNull(13)) {
wallMessage.views = Integer.valueOf(query.getInt(13));
}
wallMessage.statistics = deserializeStats(query.getBlob(14));
wallMessage.ad_data = query.getString(15);
wallMessage.track_code = query.getString(16);
wallMessage.attachments = deserializeAttachments(query.getBlob(17), j2);
wallMessage.copyright_link = query.getString(18);
wallMessage.copyright_name = query.getString(19);
query.close();
return wallMessage;
}
public WallMessage fetchWallPostFull(long j, long j2, long j3) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("select w.post_id as post_id, w.date as date, w.from_id as from_id, w.text as text, w.to_id as to_id, w.likes_count as likes_count, wl.[like] as [like], wl.reposted as reposted, w.signer_id as signer_id, w.reposts_count as reposts_count,w.comments_count as comments_count, w.copy_owner_id as copy_owner_id, w.copy_text as copy_text, w.post_type as post_type, w.views as views, w.attachments as attachments, w.copyright_link as copyright_link, w.copyright_name as copyright_name, w.created_by as created_by from wall as w left join wall_like as wl on wl.wall_owner_id=? AND wl.post_id=? AND wl.account_id=? AND wl.type=0 where w.to_id=? AND w.post_id=?limit 0,1", new String[]{Long.toString(j2), Long.toString(j), Long.toString(j3), Long.toString(j2), Long.toString(j)});
if (rawQuery.getCount() == 0) {
rawQuery.close();
return null;
}
rawQuery.moveToFirst();
WallMessage wallMessage = new WallMessage();
wallMessage.id = j;
wallMessage.to_id = j2;
wallMessage.text = rawQuery.getString(rawQuery.getColumnIndex("text"));
wallMessage.from_id = rawQuery.getLong(rawQuery.getColumnIndex("from_id"));
wallMessage.copy_owner_id = rawQuery.getLong(rawQuery.getColumnIndex("copy_owner_id"));
wallMessage.copy_text = rawQuery.getString(rawQuery.getColumnIndex("copy_text"));
wallMessage.date = rawQuery.getLong(rawQuery.getColumnIndex("date"));
wallMessage.comment_count = rawQuery.getLong(rawQuery.getColumnIndex("comments_count"));
wallMessage.like_count = rawQuery.getInt(rawQuery.getColumnIndex("likes_count"));
wallMessage.user_like = rawQuery.getInt(rawQuery.getColumnIndex("like")) == 1;
wallMessage.signer_id = rawQuery.getLong(rawQuery.getColumnIndex("signer_id"));
wallMessage.reposts_count = rawQuery.getInt(rawQuery.getColumnIndex("reposts_count"));
wallMessage.post_type = rawQuery.getInt(rawQuery.getColumnIndex("post_type"));
int columnIndex = rawQuery.getColumnIndex("views");
if (!rawQuery.isNull(columnIndex)) {
wallMessage.views = Integer.valueOf(rawQuery.getInt(columnIndex));
}
int columnIndex2 = rawQuery.getColumnIndex("reposted");
if (!rawQuery.isNull(columnIndex2)) {
wallMessage.user_reposted = rawQuery.getInt(columnIndex2) == 1;
}
wallMessage.copyright_link = rawQuery.getString(rawQuery.getColumnIndex("copyright_link"));
wallMessage.copyright_name = rawQuery.getString(rawQuery.getColumnIndex("copyright_name"));
wallMessage.created_by = rawQuery.getLong(rawQuery.getColumnIndex("created_by"));
wallMessage.attachments = deserializeAttachments(rawQuery.getBlob(rawQuery.getColumnIndex("attachments")), j3);
rawQuery.close();
return wallMessage;
}
public Cursor fetchWallPosts(long j, long j2) {
return this.mDbHelper.getWritableDatabase().rawQuery("select w._id as _id, w.post_id as post_id, w.date as date, w.from_id as from_id, w.text as text, w.to_id as to_id, w.likes_count as likes_count, wl.[like] as [like], wl.reposted as reposted, w.signer_id as signer_id, w.reposts_count as reposts_count,w.comments_count as comments_count, w.copy_owner_id as copy_owner_id, w.copy_text as copy_text, w.post_type as post_type, w.is_pinned as is_pinned, w.copyright_name as copyright_name, w.copyright_link as copyright_link, g.photo_medium as photo_medium, g.name as name, w.attachments as attachments, u.first_name as first_name, u.last_name as last_name, u.photo_medium_rec as photo_medium_rec, w.views as views from wall as w left join users as u on w.from_id=u._id left join groups as g on -w.from_id=g._id left join wall_like as wl on wl.wall_owner_id=? AND wl.post_id=w.post_id AND wl.account_id=? AND wl.type=0 where w.to_id=? order by w._id", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j)});
}
public HashMap getDownloadStates() {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("select audio_id, status, owner_id from audio_cache;", null);
HashMap hashMap = new HashMap();
while (rawQuery.moveToNext()) {
hashMap.put(rawQuery.getLong(2) + "_" + rawQuery.getLong(0), Integer.valueOf(rawQuery.getInt(1)));
}
rawQuery.close();
return hashMap;
}
public HashMap getDownloadVideoStates() {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("select video_id, owner_id, status from video_cache;", null);
HashMap hashMap = new HashMap();
while (rawQuery.moveToNext()) {
hashMap.put(rawQuery.getLong(1) + "_" + rawQuery.getLong(0), Integer.valueOf(rawQuery.getInt(2)));
}
rawQuery.close();
return hashMap;
}
public int getDownloadVideoStatus(long j, long j2) {
int i;
Cursor query = this.mDbHelper.getWritableDatabase().query("video_cache", null, "video_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, null);
if (query.getCount() > 0) {
query.moveToFirst();
i = query.getInt(query.getColumnIndex("status"));
} else {
i = -1;
}
query.close();
return i;
}
public Video getFirstVideoCacheJob(int i) {
Video video;
Cursor query = this.mDbHelper.getWritableDatabase().query("video_cache", null, "status=?", toArg(i), null, null, "_id", "1");
if (query.getCount() != 0) {
query.moveToFirst();
video = new Video();
video.vid = query.getLong(query.getColumnIndex("video_id"));
video.owner_id = query.getLong(query.getColumnIndex("owner_id"));
video.access_key = query.getString(query.getColumnIndex("access_key"));
} else {
video = null;
}
query.close();
return video;
}
public String getFullMentionForBot(long j) {
StringBuilder sb = new StringBuilder();
sb.append("@club");
long j2 = j * (-1);
sb.append(j2);
String sb2 = sb.toString();
Group fetchGroup = fetchGroup(j2);
if (fetchGroup != null) {
return sb2 + " (" + fetchGroup.name + ")";
}
return sb2;
}
public long getLastNewsDate(long j) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT MAX(date) FROM news WHERE account_id=? AND is_comments=0", toArg(j));
if (rawQuery == null) {
return 0L;
}
rawQuery.moveToFirst();
if (rawQuery.getCount() == 0) {
rawQuery.close();
return 0L;
}
long j2 = rawQuery.getLong(0);
rawQuery.close();
return j2;
}
public long getLastNewsDate2(long j, int i) {
long j2;
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT date FROM news WHERE account_id=? AND is_comments=? ORDER BY _id LIMIT 1", new String[]{Long.toString(j), Long.toString(i)});
if (rawQuery.getCount() != 0) {
rawQuery.moveToFirst();
j2 = rawQuery.getLong(0);
} else {
j2 = 0;
}
rawQuery.close();
return j2;
}
public ArrayList getPhotos(Cursor cursor) {
ArrayList arrayList = new ArrayList();
try {
int columnIndex = cursor.getColumnIndex("album_id");
while (cursor.moveToNext()) {
Photo photo = new Photo();
String string = cursor.getString(cursor.getColumnIndex("photo_id"));
if (string != null && string.length() != 0) {
photo.pid = Long.parseLong(string);
}
photo.src = cursor.getString(cursor.getColumnIndex("src"));
photo.src_big = cursor.getString(cursor.getColumnIndex("src_big"));
photo.src_xbig = cursor.getString(cursor.getColumnIndex("src_xbig"));
photo.src_xxbig = cursor.getString(cursor.getColumnIndex("src_xxbig"));
photo.src_xxxbig = cursor.getString(cursor.getColumnIndex("src_xxxbig"));
photo.owner_id = Long.toString(cursor.getLong(cursor.getColumnIndex("owner_id")));
photo.phototext = cursor.getString(cursor.getColumnIndex("phototext"));
if (columnIndex != -1) {
photo.aid = cursor.getLong(columnIndex);
}
int columnIndex2 = cursor.getColumnIndex("like");
if (columnIndex2 != -1) {
photo.user_likes = Boolean.valueOf(cursor.getLong(columnIndex2) == 1);
}
int columnIndex3 = cursor.getColumnIndex("like_count");
if (columnIndex3 != -1) {
photo.like_count = Integer.valueOf(cursor.getInt(columnIndex3));
}
int columnIndex4 = cursor.getColumnIndex("comments_count");
if (columnIndex4 != -1) {
photo.comments_count = Integer.valueOf(cursor.getInt(columnIndex4));
}
photo.lat = cursor.getString(cursor.getColumnIndex("lat"));
photo.lon = cursor.getString(cursor.getColumnIndex("lon"));
arrayList.add(photo);
}
return arrayList;
} catch (Throwable th) {
try {
th.printStackTrace();
Helper.reportError(th);
return arrayList;
} finally {
cursor.close();
}
}
}
public long getRowCount(String str) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
Cursor rawQuery = writableDatabase.rawQuery("SELECT count(*) FROM " + str, null);
rawQuery.moveToFirst();
long j = rawQuery.getLong(0);
rawQuery.close();
return j;
}
public ArrayList getUsersInMessages(long j, long j2) {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("SELECT -chat_id FROM chat WHERE account_id=? AND group_id=? AND chat_id<0 ", new String[]{Long.toString(j), Long.toString(j2)});
ArrayList arrayList = new ArrayList();
if (rawQuery == null) {
return arrayList;
}
while (rawQuery.moveToNext()) {
arrayList.add(Long.valueOf(rawQuery.getLong(0)));
}
rawQuery.close();
return arrayList;
}
public ArrayList getVideoDownloads() {
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("select vc.video_id as video_id, vc.owner_id as owner_id, v.title as title, v.duration as duration, v.image as image, v.image_big as image_big, v.player_url as player_url, v.description as description from video_cache as vc left join video as v on vc.video_id=v.video_id AND vc.owner_id=v.owner_id ORDER BY vc._id DESC", null);
ArrayList cursorToVideoArray = cursorToVideoArray(rawQuery);
rawQuery.close();
return cursorToVideoArray;
}
public void increaseUnreadCountInChat(long j, long j2, int i, long j3) {
this.mDbHelper.getWritableDatabase().execSQL("UPDATE chat SET unread_count=unread_count+? WHERE chat_id=? AND account_id=? AND group_id=?", new String[]{Integer.toString(i), Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public boolean isAdminInGroup(Long l, long j) {
Cursor cursor = null;
try {
cursor = this.mDbHelper.getWritableDatabase().query("user_group", new String[]{"_id"}, "group_id=? AND user_id=? AND admin_level=3", new String[]{Long.toString(j), Long.toString(l.longValue())}, null, null, null);
boolean z = cursor.getCount() != 0;
cursor.close();
return z;
} catch (Throwable th) {
if (cursor != null) {
cursor.close();
}
throw th;
}
}
public boolean isAdminOrEditorInGroup(Long l, long j) {
Cursor cursor = null;
try {
cursor = this.mDbHelper.getWritableDatabase().query("user_group", new String[]{"_id"}, "group_id=? AND user_id=? AND admin_level in (2,3)", new String[]{Long.toString(j), Long.toString(l.longValue())}, null, null, null);
boolean z = cursor.getCount() != 0;
cursor.close();
return z;
} catch (Throwable th) {
if (cursor != null) {
cursor.close();
}
throw th;
}
}
public boolean isAudioCached(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("audio_cache", new String[]{"_id"}, "audio_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
boolean z = query.getCount() != 0;
query.close();
return z;
}
public boolean isFriend(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("friends", new String[]{"_id"}, "owner_id=? AND friend_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
if (query == null) {
return false;
}
if (query.getCount() == 0) {
query.close();
return false;
}
query.close();
return true;
}
public boolean isJoinGroup(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("user_group", new String[]{"group_id", "user_id"}, "group_id=? AND user_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, null);
if (query == null) {
return false;
}
if (query.getCount() == 0) {
query.close();
return false;
}
query.close();
return true;
}
public boolean isModerInGroup(Long l, long j) {
Cursor cursor = null;
try {
cursor = this.mDbHelper.getWritableDatabase().query("user_group", new String[]{"_id"}, "group_id=? AND user_id=? AND admin_level in (1,2,3)", new String[]{Long.toString(j), Long.toString(l.longValue())}, null, null, null);
boolean z = cursor.getCount() != 0;
cursor.close();
return z;
} catch (Throwable th) {
if (cursor != null) {
cursor.close();
}
throw th;
}
}
public boolean isVideoCached(long j, long j2) {
Cursor query = this.mDbHelper.getWritableDatabase().query("video_cache", new String[]{"_id"}, "video_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)}, null, null, null, "1");
boolean z = query.getCount() != 0;
query.close();
return z;
}
long millisToEventTime(long j) {
return ((j / 1000) / 60) / 60;
}
public void open() {
OpenHelper openHelper = new OpenHelper(this.mCtx);
this.mDbHelper = openHelper;
openHelper.setWriteAheadLoggingEnabledWithReflection(true);
}
public void recreateChatMembers(Long l, ArrayList arrayList) {
deleteChatMembers(l.longValue());
createChatMembers(l, arrayList);
}
public void recreateComments(ArrayList arrayList, long j, int i, long j2, long j3) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
long j4 = i;
KApplication.db.deleteComments(j, j4, j2);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
KApplication.db.createComment((Comment) it.next(), j, j4, j2, j3);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void recreateMessages(ArrayList arrayList, long j, long j2, long j3, long j4) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
KApplication.db.deleteMessageThread(j, j2, j3, j4);
KApplication.db.createOrUpdateMessages(arrayList, j3, j4);
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void recreateWallPosts(long j, ArrayList arrayList, long j2) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
KApplication.db.deleteWallPosts(j);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
createOrUpdateWallPost((WallMessage) it.next(), j2, false);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public void removeVideoFromCache(long j, long j2) {
this.mDbHelper.getWritableDatabase().delete("video_cache", "video_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
byte[] serialize(Serializable serializable) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
new ObjectOutputStream(byteArrayOutputStream).writeObject(serializable);
return byteArrayOutputStream.toByteArray();
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
return null;
}
}
public void setMessageImportant(long j, boolean z, long j2, long j3) {
ContentValues contentValues = new ContentValues();
contentValues.put("important", Integer.valueOf(z ? 1 : 0));
this.mDbHelper.getWritableDatabase().update("messages", contentValues, "message_id=? AND account_id=? AND group_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public void setMessageReadState(ArrayList arrayList, boolean z, long j, long j2) {
Iterator it = arrayList.iterator();
String str = "";
while (it.hasNext()) {
Long l = (Long) it.next();
if (!str.equals("")) {
str = str + ",";
}
str = str + l;
}
ContentValues contentValues = new ContentValues();
contentValues.put("read_state", Integer.valueOf(z ? 1 : 0));
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.update("messages", contentValues, "message_id in " + ("(" + str + ")") + " AND account_id=" + j + " AND group_id=" + j2, null);
}
public void setMessagesReadState(long j, long j2, long j3) {
ContentValues contentValues = new ContentValues();
contentValues.put("read_state", (Integer) 1);
this.mDbHelper.getWritableDatabase().update("messages", contentValues, "chat_id=? AND account_id=? AND group_id=? AND read_state=0 AND is_out=1", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public void setUnreadCountInChat(long j, long j2, int i, long j3) {
this.mDbHelper.getWritableDatabase().execSQL("UPDATE chat SET unread_count=? WHERE chat_id=? AND account_id=? AND group_id=?", new String[]{Integer.toString(i), Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public void setVideoInCacheStatus(long j, long j2, int i) {
ContentValues contentValues = new ContentValues();
contentValues.put("status", Integer.valueOf(i));
this.mDbHelper.getWritableDatabase().update("video_cache", contentValues, "video_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void updateAlbum(Album album) {
ContentValues contentValues = new ContentValues();
contentValues.put("title", album.title);
contentValues.put("description", album.description);
Privacy privacy = album.privacy;
if (privacy != null) {
contentValues.put("privacy_str", privacy.toString());
}
Privacy privacy2 = album.comment_privacy;
if (privacy2 != null) {
contentValues.put("privacy_comments", privacy2.toString());
}
String str = album.thumb_src;
if (str != null) {
contentValues.put("thumb_src", str);
}
this.mDbHelper.getWritableDatabase().update("albums", contentValues, "album_id=?", toArg(album.aid));
}
public boolean updateAudio(Audio audio) {
ContentValues contentValues = new ContentValues();
long j = audio.owner_id;
if (j != 0) {
contentValues.put("owner_id", Long.valueOf(j));
}
String str = audio.artist;
if (str != null) {
contentValues.put("artist", str);
}
String str2 = audio.title;
if (str2 != null) {
contentValues.put("title", str2);
}
contentValues.put("duration", Long.valueOf(audio.duration));
String str3 = audio.url;
if (str3 != null) {
contentValues.put("url", str3);
}
Long l = audio.lyrics_id;
if (l != null) {
contentValues.put("lyrics_id", l);
}
contentValues.put("genre_id", Integer.valueOf(audio.track_genre_id));
return this.mDbHelper.getWritableDatabase().update("audio", contentValues, "audio_id=? AND owner_id=?", new String[]{Long.toString(audio.aid), Long.toString(audio.owner_id)}) > 0;
}
public boolean updateChat(Message message, long j, long j2, long j3) {
ContentValues contentValues = new ContentValues();
contentValues.put("title", message.title);
contentValues.put("photo_100", message.photo_100);
contentValues.put("unread_count", Integer.valueOf(message.unread_count));
return this.mDbHelper.getWritableDatabase().update("chat", contentValues, "chat_id=? AND account_id=? AND group_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)}) > 0;
}
public void updateChatPhoto(long j, String str, long j2) {
ContentValues contentValues = new ContentValues();
contentValues.put("photo_100", str);
this.mDbHelper.getWritableDatabase().update("chat", contentValues, "chat_id=? AND account_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void updateChatTitle(long j, String str, long j2) {
ContentValues contentValues = new ContentValues();
contentValues.put("title", str);
this.mDbHelper.getWritableDatabase().update("chat", contentValues, "chat_id=? AND account_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void updateCommentLikes(long j, long j2, long j3, long j4, Long l, boolean z, long j5) {
ContentValues contentValues = new ContentValues();
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
if (l != null) {
contentValues.put("like_count", l);
writableDatabase.update("comments", contentValues, "content_id=? AND content_type=? AND content_owner_id=? AND comment_id=?", new String[]{Long.toString(j2), Long.toString(j4), Long.toString(j3), Long.toString(j)});
}
int contentTypeToLikeType = contentTypeToLikeType(j4);
if (contentTypeToLikeType != -1) {
createOrUpdateWallLike(j3, j, j5, z, contentTypeToLikeType);
}
}
public void updateDocTitle(long j, long j2, String str) {
ContentValues contentValues = new ContentValues();
contentValues.put("title", str);
this.mDbHelper.getWritableDatabase().update("docs", contentValues, "doc_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public boolean updateGroup(Group group, boolean z) {
ContentValues contentValues = new ContentValues();
String str = group.name;
if (str != null) {
contentValues.put("name", str);
contentValues.put("name_lower", group.name.toLowerCase());
}
String str2 = group.photo;
if (str2 != null) {
contentValues.put("photo", str2);
}
String str3 = group.photo_medium;
if (str3 != null) {
contentValues.put("photo_medium", str3);
}
String str4 = group.photo_big;
if (str4 != null) {
contentValues.put("photo_big", str4);
}
Integer num = group.is_closed;
if (num != null) {
contentValues.put("is_closed", num);
}
String str5 = group.description;
if (str5 != null) {
contentValues.put("description", str5);
}
String str6 = group.wiki_page;
if (str6 != null) {
contentValues.put("wiki", str6);
}
Long l = group.fixed_post;
if (l != null) {
contentValues.put("fixed_post", l);
}
Boolean bool = group.can_see_all_posts;
if (bool != null) {
contentValues.put("can_see_all_posts", bool);
}
Integer num2 = group.members_count;
if (num2 != null) {
contentValues.put("members_count", num2);
}
Integer num3 = group.type;
if (num3 != null) {
contentValues.put("type", num3);
}
Long l2 = group.start_date;
if (l2 != null) {
contentValues.put("start_date", l2);
}
String str7 = group.status;
if (str7 != null) {
contentValues.put("status", str7);
}
if (z) {
Integer num4 = group.photos_count;
if (num4 != null) {
contentValues.put("photos", num4);
}
Integer num5 = group.albums_count;
if (num5 != null) {
contentValues.put("albums", num5);
}
Integer num6 = group.topics_count;
if (num6 != null) {
contentValues.put("topics", num6);
}
Integer num7 = group.videos_count;
if (num7 != null) {
contentValues.put("videos", num7);
}
Integer num8 = group.audios_count;
if (num8 != null) {
contentValues.put("audios", num8);
}
Integer num9 = group.docs_count;
if (num9 != null) {
contentValues.put("docs", num9);
}
Integer num10 = group.podcasts_count;
if (num10 != null) {
contentValues.put("podcasts", num10);
}
}
Integer num11 = group.verified;
if (num11 != null) {
contentValues.put("verified", num11);
}
Boolean bool2 = group.can_message;
if (bool2 != null) {
contentValues.put("can_message", bool2);
}
Boolean bool3 = group.market_enabled;
if (bool3 != null) {
contentValues.put("market_enabled", bool3);
}
Long l3 = group.market_contact_id;
if (l3 != null) {
contentValues.put("market_contact_id", l3);
}
Page page = group.market_wiki;
if (page != null) {
contentValues.put("market_wiki_id", Long.valueOf(page.id));
contentValues.put("market_wiki_title", group.market_wiki.title);
}
String str8 = group.cover_400;
if (str8 != null) {
contentValues.put("cover_400", str8);
}
String str9 = group.cover_800;
if (str9 != null) {
contentValues.put("cover_800", str9);
}
return this.mDbHelper.getWritableDatabase().update("groups", contentValues, "_id=?", toArg(group.gid)) > 0;
}
public void updateGroupStatus(long j, String str) {
ContentValues contentValues = new ContentValues();
contentValues.put("status", str);
this.mDbHelper.getWritableDatabase().update("groups", contentValues, "_id= ?", toArg(j));
}
public boolean updateGroupTopic(GroupTopic groupTopic) {
ContentValues contentValues = new ContentValues();
contentValues.put("group_id", Long.valueOf(groupTopic.gid));
contentValues.put("title", groupTopic.title);
contentValues.put("title_lower", groupTopic.title.toLowerCase());
contentValues.put("comments", Integer.valueOf(groupTopic.comments));
contentValues.put("created", Long.valueOf(groupTopic.created));
contentValues.put("created_by", Long.valueOf(groupTopic.created_by));
contentValues.put("updated", Long.valueOf(groupTopic.updated));
contentValues.put("updated_by", Long.valueOf(groupTopic.updated_by));
contentValues.put("is_closed", Integer.valueOf(groupTopic.is_closed));
contentValues.put("is_fixed", Integer.valueOf(groupTopic.is_fixed));
return this.mDbHelper.getWritableDatabase().update("group_topics", contentValues, "_id=?", toArg(groupTopic.tid)) > 0;
}
public void updateGroupWallCount(long j, Integer num) {
if (num == null) {
return;
}
ContentValues contentValues = new ContentValues();
contentValues.put("posts", num);
this.mDbHelper.getWritableDatabase().update("groups", contentValues, "_id= ?", toArg(j));
}
public boolean updateMessage(Message message, long j, long j2) {
ContentValues contentValues = new ContentValues();
contentValues.put("read_state", Integer.valueOf(message.read_state ? 1 : 0));
long j3 = message.update_time;
if (j3 != 0) {
contentValues.put("update_time", Long.valueOf(j3));
}
Boolean bool = message.important;
if (bool != null) {
contentValues.put("important", Integer.valueOf(bool.booleanValue() ? 1 : 0));
}
return this.mDbHelper.getWritableDatabase().update("messages", contentValues, "message_id=? AND account_id=? AND group_id=?", new String[]{Long.toString(message.mid), Long.toString(j), Long.toString(j2)}) > 0;
}
public void updateMessageText(long j, long j2, long j3, String str) {
ContentValues contentValues = new ContentValues();
contentValues.put("body", str);
contentValues.put("update_time", Long.valueOf(System.currentTimeMillis() / 1000));
this.mDbHelper.getWritableDatabase().update("messages", contentValues, "message_id=? AND account_id=? AND group_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
public boolean updateNote(Note note) {
ContentValues contentValues = new ContentValues();
String str = note.text;
if (str != null) {
contentValues.put("text", str);
}
contentValues.put("title", note.title);
long j = note.ncom;
if (j != -1) {
contentValues.put("comments", Long.valueOf(j));
}
long j2 = note.date;
if (j2 != 0) {
contentValues.put("date", Long.valueOf(j2));
}
contentValues.put("from_id", Long.valueOf(note.owner_id));
return this.mDbHelper.getWritableDatabase().update("notes", contentValues, "_id=?", toArg(note.nid)) > 0;
}
public boolean updatePhoto(Photo photo) {
ContentValues contentValues = new ContentValues();
String str = photo.src;
if (str != null && !str.equals("")) {
contentValues.put("src", photo.src);
}
String str2 = photo.src_big;
if (str2 != null && !str2.equals("")) {
contentValues.put("src_big", photo.src_big);
}
String str3 = photo.src_xbig;
if (str3 != null && !str3.equals("")) {
contentValues.put("src_xbig", photo.src_xbig);
}
String str4 = photo.src_xxbig;
if (str4 != null && !str4.equals("")) {
contentValues.put("src_xxbig", photo.src_xxbig);
}
String str5 = photo.src_xxxbig;
if (str5 != null && !str5.equals("")) {
contentValues.put("src_xxxbig", photo.src_xxxbig);
}
long j = photo.aid;
if (j != 0) {
contentValues.put("album_id", Long.valueOf(j));
}
String str6 = photo.phototext;
if (str6 != null && !str6.equals("")) {
contentValues.put("phototext", photo.phototext);
}
long j2 = photo.created;
if (j2 != 0) {
contentValues.put("created", Long.valueOf(j2));
}
Integer num = photo.like_count;
if (num != null) {
contentValues.put("like_count", num);
}
Integer num2 = photo.comments_count;
if (num2 != null) {
contentValues.put("comments_count", num2);
}
int i = photo.width;
if (i != 0) {
contentValues.put("width", Integer.valueOf(i));
}
int i2 = photo.height;
if (i2 != 0) {
contentValues.put("height", Integer.valueOf(i2));
}
String str7 = photo.lat;
if (str7 != null) {
contentValues.put("lat", str7);
}
String str8 = photo.lon;
if (str8 != null) {
contentValues.put("lon", str8);
}
return this.mDbHelper.getWritableDatabase().update("photos", contentValues, "photo_id=? AND owner_id=?", new String[]{Long.toString(photo.pid), photo.owner_id}) > 0;
}
public void updatePhotoAlbumId(long j, long j2, long j3) {
ContentValues contentValues = new ContentValues();
contentValues.put("album_id", Long.valueOf(j3));
this.mDbHelper.getWritableDatabase().update("photos", contentValues, "photo_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void updatePhotoLikes(long j, long j2, long j3) {
ContentValues contentValues = new ContentValues();
contentValues.put("like_count", Long.valueOf(j3));
this.mDbHelper.getWritableDatabase().update("photos", contentValues, "photo_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public void updatePhotoText(long j, long j2, String str) {
ContentValues contentValues = new ContentValues();
contentValues.put("phototext", str);
this.mDbHelper.getWritableDatabase().update("photos", contentValues, "photo_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public boolean updatePoll(VkPoll vkPoll, long j) {
ContentValues contentValues = new ContentValues();
contentValues.put("question", vkPoll.question);
long j2 = vkPoll.owner_id;
if (j2 != 0) {
contentValues.put("owner_id", Long.valueOf(j2));
}
Long l = vkPoll.created;
if (l != null) {
contentValues.put("created", l);
}
Long l2 = vkPoll.votes;
if (l2 != null) {
contentValues.put("votes", l2);
}
String str = vkPoll.answers_json;
if (str != null) {
contentValues.put("answers", str);
}
contentValues.put("anonymous", Integer.valueOf(vkPoll.anonymous ? 1 : 0));
return this.mDbHelper.getWritableDatabase().update("poll", contentValues, "poll_id=? AND account_id=?", new String[]{Long.toString(vkPoll.id), Long.toString(j)}) > 0;
}
public void updatePostLikes(long j, long j2, Long l, Boolean bool, long j3, Integer num, Boolean bool2) {
ContentValues contentValues = new ContentValues();
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
if (l != null) {
contentValues.put("likes_count", l);
}
if (num != null) {
contentValues.put("reposts_count", num);
}
if (contentValues.size() > 0) {
writableDatabase.update("wall", contentValues, "post_id=? AND to_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
contentValues.clear();
if (l != null) {
contentValues.put("like_count", l);
}
if (num != null) {
contentValues.put("reposts_count", num);
}
if (bool != null) {
contentValues.put("user_like", Integer.valueOf(bool.booleanValue() ? 1 : 0));
}
if (bool2 != null) {
contentValues.put("user_reposted", Integer.valueOf(bool2.booleanValue() ? 1 : 0));
}
if (contentValues.size() > 0) {
writableDatabase.update("news", contentValues, "post_id=? AND source_id=? AND account_id=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3)});
}
if (bool != null) {
createOrUpdateWallLike(j2, j, j3, bool.booleanValue(), 0, bool2);
}
}
public void updateStatus(long j, String str) {
ContentValues contentValues = new ContentValues();
contentValues.put("status", str);
this.mDbHelper.getWritableDatabase().update("users", contentValues, "_id= ?", toArg(j));
}
public void updateTopicCloseFlag(long j, boolean z) {
ContentValues contentValues = new ContentValues();
contentValues.put("is_closed", Integer.valueOf(!z ? 1 : 0));
this.mDbHelper.getWritableDatabase().update("group_topics", contentValues, "_id=?", new String[]{Long.toString(j)});
}
public void updateTopicFixedFlag(long j, boolean z) {
ContentValues contentValues = new ContentValues();
contentValues.put("is_fixed", Integer.valueOf(z ? 1 : 0));
this.mDbHelper.getWritableDatabase().update("group_topics", contentValues, "_id=?", new String[]{Long.toString(j)});
}
public void updateTopicTitle(long j, String str) {
ContentValues contentValues = new ContentValues();
contentValues.put("title", str);
this.mDbHelper.getWritableDatabase().update("group_topics", contentValues, "_id=?", new String[]{Long.toString(j)});
}
public boolean updateUser(User user, boolean z) {
int i;
ContentValues contentValues = new ContentValues();
String str = user.first_name;
if (str != null) {
contentValues.put("first_name", str);
contentValues.put("first_name_lower", user.first_name.toLowerCase());
}
String str2 = user.last_name;
if (str2 != null) {
contentValues.put("last_name", str2);
contentValues.put("last_name_lower", user.last_name.toLowerCase());
}
String str3 = user.nickname;
if (str3 != null) {
contentValues.put("nickname", str3);
contentValues.put("nickname_lower", user.nickname.toLowerCase());
}
String str4 = user.photo;
if (str4 != null) {
contentValues.put("photo", str4);
}
String str5 = user.photo_medium_rec;
if (str5 != null) {
contentValues.put("photo_medium_rec", str5);
}
String str6 = user.photo_big;
if (str6 != null) {
contentValues.put("photo_big", str6);
}
String str7 = user.photo_200;
if (str7 != null) {
contentValues.put("photo_200", str7);
}
String str8 = user.photo_400_orig;
if (str8 != null) {
contentValues.put("photo_400_orig", str8);
}
String str9 = user.domain;
if (str9 != null) {
contentValues.put("domain", str9);
}
Integer num = user.sex;
if (num != null) {
contentValues.put("sex", num);
}
String str10 = user.birthdate;
if (str10 != null) {
contentValues.put("birthdate", str10);
}
Integer num2 = user.city;
if (num2 != null) {
contentValues.put("city", num2);
}
Integer num3 = user.country;
if (num3 != null) {
contentValues.put("country", num3);
}
Integer num4 = user.rate;
if (num4 != null) {
contentValues.put("rate", num4);
}
String str11 = user.mobile_phone;
if (str11 != null) {
contentValues.put("mobile_phone", str11);
}
String str12 = user.home_phone;
if (str12 != null) {
contentValues.put("home_phone", str12);
}
Integer num5 = user.university;
if (num5 != null) {
contentValues.put("university", num5);
}
String str13 = user.university_name;
if (str13 != null) {
contentValues.put("university_name", str13);
}
Integer num6 = user.faculty;
if (num6 != null) {
contentValues.put("faculty", num6);
}
String str14 = user.faculty_name;
if (str14 != null) {
contentValues.put("faculty_name", str14);
}
Integer num7 = user.graduation;
if (num7 != null) {
contentValues.put("graduation", num7);
}
Boolean bool = user.online;
if (bool != null) {
contentValues.put("online", Integer.valueOf(bool.booleanValue() ? 1 : 0));
}
Boolean bool2 = user.online_mobile;
if (bool2 != null) {
contentValues.put("online_mobile", Integer.valueOf(bool2.booleanValue() ? 1 : 0));
}
String str15 = user.status;
if (str15 != null) {
contentValues.put("status", str15);
}
Integer num8 = user.relation;
if (num8 != null) {
contentValues.put("relation", num8);
}
long j = user.last_seen;
if (j > 0) {
contentValues.put("last_seen", Long.valueOf(j));
}
Boolean bool3 = user.online;
if (bool3 != null && !bool3.booleanValue() && (i = user.last_seen_platform) != 0) {
contentValues.put("online_mobile", Boolean.valueOf(i < 7));
}
if (z) {
contentValues.put("albums", Integer.valueOf(user.albums_count));
contentValues.put("photos", Integer.valueOf(user.photo_count));
contentValues.put("videos", Integer.valueOf(user.videos_count));
contentValues.put("audios", Integer.valueOf(user.audios_count));
contentValues.put("notes", Integer.valueOf(user.notes_count));
contentValues.put("friends", Integer.valueOf(user.friends_count));
Integer num9 = user.online_friends_count;
if (num9 != null) {
contentValues.put("online_friends", num9);
}
Integer num10 = user.mutual_friends_count;
if (num10 != null) {
contentValues.put("mutual_friends", num10);
}
contentValues.put("user_photos", Integer.valueOf(user.user_photos_count));
contentValues.put("groups", Integer.valueOf(user.groups_count));
contentValues.put("followers", Integer.valueOf(user.followers_count));
contentValues.put("gifts", Integer.valueOf(user.gifts_count));
}
Integer num11 = user.verified;
if (num11 != null) {
contentValues.put("verified", num11);
}
User.Rect rect = user.crop_photo_rect;
if (rect != null) {
contentValues.put("crop_photo_rect_x1", Double.valueOf(rect.x1));
contentValues.put("crop_photo_rect_x2", Double.valueOf(user.crop_photo_rect.x2));
contentValues.put("crop_photo_rect_y1", Double.valueOf(user.crop_photo_rect.y1));
contentValues.put("crop_photo_rect_y2", Double.valueOf(user.crop_photo_rect.y2));
}
String str16 = user.cover_400;
if (str16 != null) {
contentValues.put("cover_400", str16);
}
String str17 = user.cover_960;
if (str17 != null) {
contentValues.put("cover_960", str17);
}
return this.mDbHelper.getWritableDatabase().update("users", contentValues, "_id= ?", toArg(user.uid)) > 0;
}
public void updateUserOnlineStatus(long j, boolean z) {
ContentValues contentValues = new ContentValues();
contentValues.put("online", Integer.valueOf(z ? 1 : 0));
this.mDbHelper.getWritableDatabase().update("users", contentValues, "_id= ?", toArg(j));
}
public void updateUserWallCount(long j, Integer[] numArr) {
ContentValues contentValues = new ContentValues();
Integer num = numArr[0];
if (num != null) {
contentValues.put("posts", num);
}
Integer num2 = numArr[1];
if (num2 != null) {
contentValues.put("notes", num2);
}
if (contentValues.size() == 0) {
return;
}
this.mDbHelper.getWritableDatabase().update("users", contentValues, "_id= ?", toArg(j));
}
public void updateUsersOnlineStatus(ArrayList arrayList, long j) {
SQLiteDatabase writableDatabase = this.mDbHelper.getWritableDatabase();
writableDatabase.beginTransaction();
try {
writableDatabase.execSQL("update users set online=0 where _id in (select friend_id from friends where owner_id=?)", toArg(j));
if (arrayList.size() > 0) {
String str = "";
Iterator it = arrayList.iterator();
while (it.hasNext()) {
long longValue = ((Long) it.next()).longValue();
if (str.length() != 0) {
str = str + ',';
}
str = str + longValue;
}
ContentValues contentValues = new ContentValues();
contentValues.put("online", (Integer) 1);
writableDatabase.update("users", contentValues, "_id in (" + str + ")", null);
}
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
long longValue2 = ((Long) it2.next()).longValue();
if (!isFriend(j, longValue2)) {
createFriend(j, longValue2);
}
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
public boolean updateVideo(Video video) {
ContentValues contentValues = new ContentValues();
String str = video.title;
if (str != null) {
contentValues.put("title", str);
}
String str2 = video.description;
if (str2 != null) {
contentValues.put("description", str2);
}
long j = video.duration;
if (j != 0) {
contentValues.put("duration", Long.valueOf(j));
}
String str3 = video.image;
if (str3 != null && !str3.equals("")) {
contentValues.put("image", video.image);
}
String str4 = video.image_big;
if (str4 != null && !str4.equals("")) {
contentValues.put("image_big", video.image_big);
}
long j2 = video.date;
if (j2 != 0) {
contentValues.put("date", Long.valueOf(j2));
}
String str5 = video.player;
if (str5 != null && !str5.equals("")) {
contentValues.put("player_url", video.player);
}
int i = video.views;
if (i != 0) {
contentValues.put("views", Integer.valueOf(i));
}
Integer num = video.like_count;
if (num != null) {
contentValues.put("likes_count", num);
}
String str6 = video.platform;
if (str6 != null) {
contentValues.put("platform", str6);
}
return this.mDbHelper.getWritableDatabase().update("video", contentValues, "video_id=? AND owner_id=?", new String[]{Long.toString(video.vid), Long.toString(video.owner_id)}) > 0;
}
public void updateVideoLikeCount(long j, long j2, int i) {
ContentValues contentValues = new ContentValues();
contentValues.put("likes_count", Integer.valueOf(i));
this.mDbHelper.getWritableDatabase().update("video", contentValues, "video_id=? AND owner_id=?", new String[]{Long.toString(j), Long.toString(j2)});
}
public int updateWallLike(long j, long j2, long j3, boolean z, int i, Boolean bool) {
ContentValues contentValues = new ContentValues();
contentValues.put("like", Integer.valueOf(z ? 1 : 0));
if (bool != null) {
contentValues.put("reposted", Integer.valueOf(bool.booleanValue() ? 1 : 0));
}
return this.mDbHelper.getWritableDatabase().update("wall_like", contentValues, "wall_owner_id=? AND post_id=? AND account_id=? AND type=?", new String[]{Long.toString(j), Long.toString(j2), Long.toString(j3), Long.toString(i)});
}
public void updateWallPost(WallMessage wallMessage, long j, long j2) {
ContentValues contentValues = new ContentValues();
contentValues.put("comments_count", Long.valueOf(wallMessage.comment_count));
contentValues.put("post_type", Integer.valueOf(wallMessage.post_type));
contentValues.put("likes_count", Integer.valueOf(wallMessage.like_count));
createOrUpdateWallLike(wallMessage.to_id, wallMessage.id, j, wallMessage.user_like, 0, Boolean.valueOf(wallMessage.user_reposted));
contentValues.put("reposts_count", Integer.valueOf(wallMessage.reposts_count));
contentValues.put("is_pinned", Integer.valueOf(wallMessage.is_pinned ? 1 : 0));
Integer num = wallMessage.views;
if (num != null) {
contentValues.put("views", num);
}
contentValues.put("attachments", serializeAttachments(wallMessage.attachments));
this.mDbHelper.getWritableDatabase().update("wall", contentValues, "post_id=? AND to_id=?", new String[]{Long.toString(wallMessage.id), Long.toString(wallMessage.to_id)});
}
public void vacuum() {
this.mDbHelper.getWritableDatabase().execSQL("VACUUM;");
}
public boolean videoExists(long j, long j2) {
boolean z = false;
Cursor rawQuery = this.mDbHelper.getWritableDatabase().rawQuery("select count(*) from video where video_id=? AND owner_id=?;", new String[]{Long.toString(j), Long.toString(j2)});
if (rawQuery.moveToNext() && rawQuery.getInt(0) != 0) {
z = true;
}
rawQuery.close();
return z;
}
}