use of org.telegram.ui.Components.WallpaperUpdater in project Telegram-FOSS by Telegram-FOSS-Team.
the class WallpapersListActivity method createView.
@Override
public View createView(Context context) {
colorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
colorFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
colorFramePaint.setStrokeWidth(AndroidUtilities.dp(1));
colorFramePaint.setStyle(Paint.Style.STROKE);
colorFramePaint.setColor(0x33000000);
updater = new WallpaperUpdater(getParentActivity(), this, new WallpaperUpdater.WallpaperUpdaterDelegate() {
@Override
public void didSelectWallpaper(File file, Bitmap bitmap, boolean gallery) {
presentFragment(new ThemePreviewActivity(new FileWallpaper("", file, file), bitmap), gallery);
}
@Override
public void needOpenColorPicker() {
}
});
hasOwnBackground = true;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (currentType == TYPE_ALL) {
actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
} else if (currentType == TYPE_COLOR) {
actionBar.setTitle(LocaleController.getString("SelectColorTitle", R.string.SelectColorTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (actionBar.isActionModeShowed()) {
selectedWallPapers.clear();
actionBar.hideActionMode();
updateRowsSelection();
} else {
finishFragment();
}
} else if (id == delete) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.formatPluralString("DeleteBackground", selectedWallPapers.size()));
builder.setMessage(LocaleController.formatString("DeleteChatBackgroundsAlert", R.string.DeleteChatBackgroundsAlert));
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
ArrayList<Integer> ids = new ArrayList<>();
int[] deleteCount = new int[] { 0 };
for (int b = 0; b < selectedWallPapers.size(); b++) {
Object object = selectedWallPapers.valueAt(b);
if (object instanceof ColorWallpaper) {
ColorWallpaper colorWallpaper = (ColorWallpaper) object;
if (colorWallpaper.parentWallpaper != null && colorWallpaper.parentWallpaper.id < 0) {
getMessagesStorage().deleteWallpaper(colorWallpaper.parentWallpaper.id);
localWallPapers.remove(colorWallpaper);
localDict.remove(colorWallpaper.getHash());
} else {
object = colorWallpaper.parentWallpaper;
}
}
if (!(object instanceof TLRPC.WallPaper)) {
continue;
}
deleteCount[0]++;
TLRPC.WallPaper wallPaper = (TLRPC.WallPaper) object;
TLRPC.TL_account_saveWallPaper req = new TLRPC.TL_account_saveWallPaper();
req.settings = new TLRPC.TL_wallPaperSettings();
req.unsave = true;
if (object instanceof TLRPC.TL_wallPaperNoFile) {
TLRPC.TL_inputWallPaperNoFile inputWallPaper = new TLRPC.TL_inputWallPaperNoFile();
inputWallPaper.id = wallPaper.id;
req.wallpaper = inputWallPaper;
} else {
TLRPC.TL_inputWallPaper inputWallPaper = new TLRPC.TL_inputWallPaper();
inputWallPaper.id = wallPaper.id;
inputWallPaper.access_hash = wallPaper.access_hash;
req.wallpaper = inputWallPaper;
}
if (wallPaper.slug != null && wallPaper.slug.equals(selectedBackgroundSlug)) {
selectedBackgroundSlug = Theme.hasWallpaperFromTheme() ? Theme.THEME_BACKGROUND_SLUG : Theme.DEFAULT_BACKGROUND_SLUG;
Theme.getActiveTheme().setOverrideWallpaper(null);
Theme.reloadWallpaper();
}
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
deleteCount[0]--;
if (deleteCount[0] == 0) {
loadWallpapers(true);
}
}));
}
if (deleteCount[0] == 0) {
loadWallpapers(true);
}
selectedWallPapers.clear();
actionBar.hideActionMode();
actionBar.closeSearchField();
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
} else if (id == forward) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 3);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate((fragment1, dids, message, param) -> {
StringBuilder fmessage = new StringBuilder();
for (int b = 0; b < selectedWallPapers.size(); b++) {
Object object = selectedWallPapers.valueAt(b);
String link;
if (object instanceof TLRPC.TL_wallPaper) {
link = AndroidUtilities.getWallPaperUrl(object);
} else if (object instanceof ColorWallpaper) {
link = ((ColorWallpaper) object).getUrl();
} else {
continue;
}
if (!TextUtils.isEmpty(link)) {
if (fmessage.length() > 0) {
fmessage.append('\n');
}
fmessage.append(link);
}
}
selectedWallPapers.clear();
actionBar.hideActionMode();
actionBar.closeSearchField();
if (dids.size() > 1 || dids.get(0) == UserConfig.getInstance(currentAccount).getClientUserId() || message != null) {
updateRowsSelection();
for (int a = 0; a < dids.size(); a++) {
long did = dids.get(a);
if (message != null) {
SendMessagesHelper.getInstance(currentAccount).sendMessage(message.toString(), did, null, null, null, true, null, null, null, true, 0, null);
}
if (!TextUtils.isEmpty(fmessage)) {
SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessage.toString(), did, null, null, null, true, null, null, null, true, 0, null);
}
}
fragment1.finishFragment();
} else {
long did = dids.get(0);
Bundle args1 = new Bundle();
args1.putBoolean("scrollToTopOnResume", true);
if (DialogObject.isEncryptedDialog(did)) {
args1.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else {
if (DialogObject.isUserDialog(did)) {
args1.putLong("user_id", did);
} else if (DialogObject.isChatDialog(did)) {
args1.putLong("chat_id", -did);
}
if (!MessagesController.getInstance(currentAccount).checkCanOpenChat(args1, fragment1)) {
return;
}
}
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
ChatActivity chatActivity = new ChatActivity(args1);
presentFragment(chatActivity, true);
SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessage.toString(), did, null, null, null, true, null, null, null, true, 0, null);
}
});
presentFragment(fragment);
}
}
});
if (currentType == TYPE_ALL) {
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
listView.setAdapter(searchAdapter);
listView.invalidate();
}
@Override
public void onSearchCollapse() {
listView.setAdapter(listAdapter);
listView.invalidate();
searchAdapter.processSearch(null, true);
searchItem.setSearchFieldCaption(null);
onCaptionCleared();
}
@Override
public void onTextChanged(EditText editText) {
searchAdapter.processSearch(editText.getText().toString(), false);
}
@Override
public void onCaptionCleared() {
searchAdapter.clearColor();
searchItem.setSearchFieldHint(LocaleController.getString("SearchBackgrounds", R.string.SearchBackgrounds));
}
});
searchItem.setSearchFieldHint(LocaleController.getString("SearchBackgrounds", R.string.SearchBackgrounds));
final ActionBarMenu actionMode = actionBar.createActionMode(false, null);
actionMode.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefault));
actionBar.setItemsColor(Theme.getColor(Theme.key_actionBarDefaultIcon), true);
actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarDefaultSelector), true);
selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
selectedMessagesCountTextView.setTextSize(18);
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedMessagesCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultIcon));
selectedMessagesCountTextView.setOnTouchListener((v, event) -> true);
actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));
actionModeViews.add(actionMode.addItemWithWidth(forward, R.drawable.msg_forward, AndroidUtilities.dp(54), LocaleController.getString("Forward", R.string.Forward)));
actionModeViews.add(actionMode.addItemWithWidth(delete, R.drawable.msg_delete, AndroidUtilities.dp(54), LocaleController.getString("Delete", R.string.Delete)));
selectedWallPapers.clear();
}
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new RecyclerListView(context) {
private Paint paint = new Paint();
@Override
public boolean hasOverlappingRendering() {
return false;
}
@Override
public void onDraw(Canvas c) {
ViewHolder holder;
if (getAdapter() == listAdapter && resetInfoRow != -1) {
holder = findViewHolderForAdapterPosition(resetInfoRow);
} else {
holder = null;
}
int bottom;
int height = getMeasuredHeight();
if (holder != null) {
bottom = holder.itemView.getBottom();
if (holder.itemView.getBottom() >= height) {
bottom = height;
}
} else {
bottom = height;
}
paint.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
c.drawRect(0, 0, getMeasuredWidth(), bottom, paint);
if (bottom != height) {
paint.setColor(Theme.getColor(Theme.key_windowBackgroundGray));
c.drawRect(0, bottom, getMeasuredWidth(), height, paint);
}
}
};
listView.setClipToPadding(false);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(false);
listView.setItemAnimator(null);
listView.setLayoutAnimation(null);
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
});
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
listView.setAdapter(listAdapter = new ListAdapter(context));
searchAdapter = new SearchAdapter(context);
listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue));
listView.setOnItemClickListener((view, position) -> {
if (getParentActivity() == null || listView.getAdapter() == searchAdapter) {
return;
}
if (position == uploadImageRow) {
updater.openGallery();
} else if (position == setColorRow) {
WallpapersListActivity activity = new WallpapersListActivity(TYPE_COLOR);
activity.patterns = patterns;
presentFragment(activity);
} else if (position == resetRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ResetChatBackgroundsAlertTitle", R.string.ResetChatBackgroundsAlertTitle));
builder.setMessage(LocaleController.getString("ResetChatBackgroundsAlert", R.string.ResetChatBackgroundsAlert));
builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
if (actionBar.isActionModeShowed()) {
selectedWallPapers.clear();
actionBar.hideActionMode();
updateRowsSelection();
}
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
TLRPC.TL_account_resetWallPapers req = new TLRPC.TL_account_resetWallPapers();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> loadWallpapers(false)));
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
});
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
scrolling = newState != RecyclerView.SCROLL_STATE_IDLE;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (listView.getAdapter() == searchAdapter) {
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
if (visibleItemCount > 0) {
int totalItemCount = layoutManager.getItemCount();
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2) {
searchAdapter.loadMoreResults();
}
}
}
}
});
searchEmptyView = new EmptyTextProgressView(context);
searchEmptyView.setVisibility(View.GONE);
searchEmptyView.setShowAtCenter(true);
searchEmptyView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
listView.setEmptyView(searchEmptyView);
frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
updateRows();
return fragmentView;
}
Aggregations