2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2013-10-25 17:19:00 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2017-03-31 01:58:05 +02:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
2013-10-25 17:19:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.graphics.Bitmap;
|
2016-04-22 15:49:00 +02:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.graphics.drawable.Drawable;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.MotionEvent;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.widget.FrameLayout;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.support.widget.LinearLayoutManager;
|
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.RequestDelegate;
|
|
|
|
import org.telegram.tgnet.TLObject;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2013-12-20 20:25:49 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.R;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Cells.WallpaperCell;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RadialProgressView;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.WallpaperUpdater;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2014-11-13 21:10:14 +01:00
|
|
|
public class WallpapersActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private ListAdapter listAdapter;
|
|
|
|
private ImageView backgroundImage;
|
2016-04-22 15:49:00 +02:00
|
|
|
private FrameLayout progressView;
|
|
|
|
private View progressViewBackground;
|
2017-03-31 01:58:05 +02:00
|
|
|
private View doneButton;
|
|
|
|
private RadialProgressView progressBar;
|
|
|
|
private RecyclerListView listView;
|
|
|
|
private WallpaperUpdater updater;
|
|
|
|
private File wallpaperFile;
|
|
|
|
private Drawable themedWallpaper;
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private int selectedBackground;
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean overrideThemeWallpaper;
|
2013-10-25 17:19:00 +02:00
|
|
|
private int selectedColor;
|
2015-02-26 02:32:51 +01:00
|
|
|
private ArrayList<TLRPC.WallPaper> wallPapers = new ArrayList<>();
|
|
|
|
private HashMap<Integer, TLRPC.WallPaper> wallpappersByIds = new HashMap<>();
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private String loadingFile = null;
|
|
|
|
private File loadingFileObject = null;
|
|
|
|
private TLRPC.PhotoSize loadingSize = null;
|
|
|
|
|
2014-11-13 21:10:14 +01:00
|
|
|
private final static int done_button = 1;
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.wallpapersDidLoaded);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 17:19:00 +02:00
|
|
|
selectedBackground = preferences.getInt("selectedBackground", 1000001);
|
2017-03-31 01:58:05 +02:00
|
|
|
overrideThemeWallpaper = preferences.getBoolean("overrideThemeWallpaper", false);
|
2013-10-25 17:19:00 +02:00
|
|
|
selectedColor = preferences.getInt("selectedColor", 0);
|
2014-03-22 23:31:55 +01:00
|
|
|
MessagesStorage.getInstance().getWallpapers();
|
2013-10-25 17:19:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2017-03-31 01:58:05 +02:00
|
|
|
updater.cleanup();
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidFailedLoad);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.wallpapersDidLoaded);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2017-03-31 01:58:05 +02:00
|
|
|
themedWallpaper = Theme.getThemedWallpaper(true);
|
|
|
|
updater = new WallpaperUpdater(getParentActivity(), new WallpaperUpdater.WallpaperUpdaterDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectWallpaper(File file, Bitmap bitmap) {
|
|
|
|
selectedBackground = -1;
|
|
|
|
overrideThemeWallpaper = true;
|
|
|
|
selectedColor = 0;
|
|
|
|
wallpaperFile = file;
|
|
|
|
Drawable drawable = backgroundImage.getDrawable();
|
|
|
|
backgroundImage.setImageBitmap(bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void needOpenColorPicker() {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setAllowOverlayTitle(true);
|
|
|
|
actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
|
|
|
} else if (id == done_button) {
|
|
|
|
boolean done;
|
|
|
|
TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
|
|
|
|
if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
|
|
|
|
int width = AndroidUtilities.displaySize.x;
|
|
|
|
int height = AndroidUtilities.displaySize.y;
|
|
|
|
if (width > height) {
|
|
|
|
int temp = width;
|
|
|
|
width = height;
|
|
|
|
height = temp;
|
|
|
|
}
|
|
|
|
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height));
|
|
|
|
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
|
|
|
|
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
2015-10-29 18:10:07 +01:00
|
|
|
File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
|
2015-04-09 20:00:14 +02:00
|
|
|
try {
|
2015-05-21 23:27:27 +02:00
|
|
|
done = AndroidUtilities.copyFile(f, toFile);
|
2015-04-09 20:00:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
done = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (selectedBackground == -1) {
|
2017-03-31 01:58:05 +02:00
|
|
|
File fromFile = updater.getCurrentWallpaperPath();
|
2015-10-29 18:10:07 +01:00
|
|
|
File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
done = AndroidUtilities.copyFile(fromFile, toFile);
|
|
|
|
} catch (Exception e) {
|
|
|
|
done = false;
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2014-04-03 12:23:39 +02:00
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
done = true;
|
2014-04-03 12:23:39 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (done) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("selectedBackground", selectedBackground);
|
|
|
|
editor.putInt("selectedColor", selectedColor);
|
2017-03-31 01:58:05 +02:00
|
|
|
editor.putBoolean("overrideThemeWallpaper", Theme.hasWallpaperFromTheme() && overrideThemeWallpaper);
|
2015-04-09 20:00:14 +02:00
|
|
|
editor.commit();
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.reloadWallpaper();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
finishFragment();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
FrameLayout frameLayout = new FrameLayout(context);
|
|
|
|
fragmentView = frameLayout;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
backgroundImage = new ImageView(context);
|
|
|
|
backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
|
frameLayout.addView(backgroundImage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
backgroundImage.setOnTouchListener(new View.OnTouchListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
progressView = new FrameLayout(context);
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
|
|
|
frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52));
|
|
|
|
|
|
|
|
progressViewBackground = new View(context);
|
|
|
|
progressViewBackground.setBackgroundResource(R.drawable.system_loader);
|
|
|
|
progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER));
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
progressBar = new RadialProgressView(context);
|
|
|
|
progressBar.setSize(AndroidUtilities.dp(28));
|
|
|
|
progressBar.setProgressColor(0xffffffff);
|
2016-04-22 15:49:00 +02:00
|
|
|
progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
listView = new RecyclerListView(context);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setClipToPadding(false);
|
2016-06-24 12:27:15 +02:00
|
|
|
listView.setTag(8);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
|
|
|
|
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
|
|
|
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
|
listView.setLayoutManager(layoutManager);
|
|
|
|
listView.setDisallowInterceptTouchEvents(true);
|
2016-06-24 12:27:15 +02:00
|
|
|
listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
|
2015-05-21 23:27:27 +02:00
|
|
|
listView.setAdapter(listAdapter = new ListAdapter(context));
|
|
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM));
|
|
|
|
listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
if (position == 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
updater.showAlert(false);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (Theme.hasWallpaperFromTheme()) {
|
|
|
|
if (position == 1) {
|
|
|
|
selectedBackground = -2;
|
|
|
|
overrideThemeWallpaper = false;
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
processSelectedBackground();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
position -= 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
position--;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
TLRPC.WallPaper wallPaper = wallPapers.get(position);
|
2015-04-09 20:00:14 +02:00
|
|
|
selectedBackground = wallPaper.id;
|
2017-03-31 01:58:05 +02:00
|
|
|
overrideThemeWallpaper = true;
|
2015-04-09 20:00:14 +02:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
processSelectedBackground();
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
processSelectedBackground();
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-26 21:16:28 +01:00
|
|
|
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
2017-03-31 01:58:05 +02:00
|
|
|
updater.onActivityResult(requestCode, resultCode, data);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-03-26 21:16:28 +01:00
|
|
|
@Override
|
|
|
|
public void saveSelfArgs(Bundle args) {
|
2017-03-31 01:58:05 +02:00
|
|
|
String currentPicturePath = updater.getCurrentPicturePath();
|
2014-03-26 21:16:28 +01:00
|
|
|
if (currentPicturePath != null) {
|
|
|
|
args.putString("path", currentPicturePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void restoreSelfArgs(Bundle args) {
|
2017-03-31 01:58:05 +02:00
|
|
|
updater.setCurrentPicturePath(args.getString("path"));
|
2014-03-26 21:16:28 +01:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private void processSelectedBackground() {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (Theme.hasWallpaperFromTheme() && !overrideThemeWallpaper) {
|
|
|
|
backgroundImage.setImageDrawable(Theme.getThemedWallpaper(false));
|
|
|
|
} else {
|
|
|
|
TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
|
|
|
|
if (selectedBackground != -1 && selectedBackground != 1000001 && wallPaper != null && wallPaper instanceof TLRPC.TL_wallPaper) {
|
|
|
|
int width = AndroidUtilities.displaySize.x;
|
|
|
|
int height = AndroidUtilities.displaySize.y;
|
|
|
|
if (width > height) {
|
|
|
|
int temp = width;
|
|
|
|
width = height;
|
|
|
|
height = temp;
|
|
|
|
}
|
|
|
|
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height));
|
|
|
|
if (size == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
|
|
|
|
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
|
|
|
if (!f.exists()) {
|
|
|
|
int result[] = AndroidUtilities.calcDrawableColor(backgroundImage.getDrawable());
|
|
|
|
progressViewBackground.getBackground().setColorFilter(new PorterDuffColorFilter(result[0], PorterDuff.Mode.MULTIPLY));
|
|
|
|
loadingFile = fileName;
|
|
|
|
loadingFileObject = f;
|
|
|
|
doneButton.setEnabled(false);
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
loadingSize = size;
|
|
|
|
selectedColor = 0;
|
2017-07-23 14:56:38 +02:00
|
|
|
FileLoader.getInstance().loadFile(size, null, 1);
|
2017-03-31 01:58:05 +02:00
|
|
|
backgroundImage.setBackgroundColor(0);
|
|
|
|
} else {
|
|
|
|
if (loadingFile != null) {
|
|
|
|
FileLoader.getInstance().cancelLoadFile(loadingSize);
|
|
|
|
}
|
|
|
|
loadingFileObject = null;
|
|
|
|
loadingFile = null;
|
|
|
|
loadingSize = null;
|
|
|
|
try {
|
|
|
|
backgroundImage.setImageURI(Uri.fromFile(f));
|
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
backgroundImage.setBackgroundColor(0);
|
|
|
|
selectedColor = 0;
|
|
|
|
doneButton.setEnabled(true);
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
|
|
|
if (loadingFile != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
FileLoader.getInstance().cancelLoadFile(loadingSize);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (selectedBackground == 1000001) {
|
|
|
|
backgroundImage.setImageResource(R.drawable.background_hd);
|
|
|
|
backgroundImage.setBackgroundColor(0);
|
|
|
|
selectedColor = 0;
|
|
|
|
} else if (selectedBackground == -1) {
|
|
|
|
File toFile;
|
|
|
|
if (wallpaperFile != null) {
|
|
|
|
toFile = wallpaperFile;
|
|
|
|
} else {
|
|
|
|
toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
|
|
|
|
}
|
|
|
|
if (toFile.exists()) {
|
|
|
|
backgroundImage.setImageURI(Uri.fromFile(toFile));
|
|
|
|
} else {
|
|
|
|
selectedBackground = 1000001;
|
|
|
|
overrideThemeWallpaper = true;
|
|
|
|
processSelectedBackground();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (wallPaper == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (wallPaper instanceof TLRPC.TL_wallPaperSolid) {
|
|
|
|
Drawable drawable = backgroundImage.getDrawable();
|
|
|
|
backgroundImage.setImageBitmap(null);
|
|
|
|
selectedColor = 0xff000000 | wallPaper.bg_color;
|
|
|
|
backgroundImage.setBackgroundColor(selectedColor);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
loadingFileObject = null;
|
|
|
|
loadingFile = null;
|
|
|
|
loadingSize = null;
|
|
|
|
doneButton.setEnabled(true);
|
2016-04-22 15:49:00 +02:00
|
|
|
progressView.setVisibility(View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, final Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.FileDidFailedLoad) {
|
2015-05-21 23:27:27 +02:00
|
|
|
String location = (String) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
if (loadingFile != null && loadingFile.equals(location)) {
|
|
|
|
loadingFileObject = null;
|
|
|
|
loadingFile = null;
|
|
|
|
loadingSize = null;
|
2016-04-22 15:49:00 +02:00
|
|
|
progressView.setVisibility(View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
doneButton.setEnabled(false);
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.FileDidLoaded) {
|
2015-05-21 23:27:27 +02:00
|
|
|
String location = (String) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
if (loadingFile != null && loadingFile.equals(location)) {
|
|
|
|
backgroundImage.setImageURI(Uri.fromFile(loadingFileObject));
|
2016-04-22 15:49:00 +02:00
|
|
|
progressView.setVisibility(View.GONE);
|
2013-10-25 17:19:00 +02:00
|
|
|
backgroundImage.setBackgroundColor(0);
|
|
|
|
doneButton.setEnabled(true);
|
|
|
|
loadingFileObject = null;
|
|
|
|
loadingFile = null;
|
|
|
|
loadingSize = null;
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.wallpapersDidLoaded) {
|
2015-05-21 23:27:27 +02:00
|
|
|
wallPapers = (ArrayList<TLRPC.WallPaper>) args[0];
|
|
|
|
wallpappersByIds.clear();
|
|
|
|
for (TLRPC.WallPaper wallPaper : wallPapers) {
|
|
|
|
wallpappersByIds.put(wallPaper.id, wallPaper);
|
|
|
|
}
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (!wallPapers.isEmpty() && backgroundImage != null) {
|
|
|
|
processSelectedBackground();
|
|
|
|
}
|
|
|
|
loadWallpapers();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadWallpapers() {
|
|
|
|
TLRPC.TL_account_getWallPapers req = new TLRPC.TL_account_getWallPapers();
|
2015-09-24 22:52:02 +02:00
|
|
|
int reqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void run(final TLObject response, TLRPC.TL_error error) {
|
2014-02-28 23:28:25 +01:00
|
|
|
if (error != null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
wallPapers.clear();
|
2015-05-21 23:27:27 +02:00
|
|
|
TLRPC.Vector res = (TLRPC.Vector) response;
|
2013-10-25 17:19:00 +02:00
|
|
|
wallpappersByIds.clear();
|
|
|
|
for (Object obj : res.objects) {
|
2015-05-21 23:27:27 +02:00
|
|
|
wallPapers.add((TLRPC.WallPaper) obj);
|
|
|
|
wallpappersByIds.put(((TLRPC.WallPaper) obj).id, (TLRPC.WallPaper) obj);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-02-26 15:36:15 +01:00
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
if (backgroundImage != null) {
|
|
|
|
processSelectedBackground();
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
MessagesStorage.getInstance().putWallpapers(wallPapers);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
});
|
2014-03-22 23:31:55 +01:00
|
|
|
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 18:00:42 +02:00
|
|
|
super.onResume();
|
2014-06-04 01:31:48 +02:00
|
|
|
if (listAdapter != null) {
|
2013-10-25 17:19:00 +02:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
processSelectedBackground();
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private Context mContext;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public int getItemCount() {
|
2017-03-31 01:58:05 +02:00
|
|
|
int count = 1 + wallPapers.size();
|
|
|
|
if (Theme.hasWallpaperFromTheme()) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
|
|
WallpaperCell view = new WallpaperCell(mContext);
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(view);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-21 23:27:27 +02:00
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
|
2017-03-31 01:58:05 +02:00
|
|
|
WallpaperCell wallpaperCell = (WallpaperCell) viewHolder.itemView;
|
|
|
|
if (i == 0) {
|
|
|
|
wallpaperCell.setWallpaper(null, !Theme.hasWallpaperFromTheme() || overrideThemeWallpaper ? selectedBackground : -2, null, false);
|
|
|
|
} else {
|
|
|
|
if (Theme.hasWallpaperFromTheme()) {
|
|
|
|
if (i == 1) {
|
|
|
|
wallpaperCell.setWallpaper(null, overrideThemeWallpaper ? -1 : -2, themedWallpaper, true);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
i -= 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
wallpaperCell.setWallpaper(wallPapers.get(i), !Theme.hasWallpaperFromTheme() || overrideThemeWallpaper ? selectedBackground : -2, null, false);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ThemeDescription[] getThemeDescriptions() {
|
|
|
|
return new ThemeDescription[]{
|
|
|
|
new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite),
|
|
|
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector),
|
|
|
|
};
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|