use of com.moez.QKSMS.ui.dialog.QKDialog in project qksms by moezbhatti.
the class DialogHelper method showChangelog.
public static void showChangelog(QKActivity context) {
context.showProgressDialog();
String url = "https://qksms-changelog.firebaseio.com/changes.json";
StringRequest request = new StringRequest(url, response -> {
Gson gson = new Gson();
ChangeModel[] changes = gson.fromJson(response, ChangeModel[].class);
// Fill in the localized date strings, and the `Long` time so that we can sort them
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd");
// For multiple updates in a day
SimpleDateFormat dateRevisionParser = new SimpleDateFormat("yyyy-MM-dd-'r'H");
SimpleDateFormat dateFormatter = new SimpleDateFormat("MMMM d, yyyy");
for (ChangeModel change : changes) {
try {
Date date;
if (change.getDate().length() > 11) {
date = dateRevisionParser.parse(change.getDate());
} else {
date = dateParser.parse(change.getDate());
}
change.setDate(dateFormatter.format(date));
change.setDateLong(date.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
}
Arrays.sort(changes, (lhs, rhs) -> Long.valueOf(rhs.getDateLong()).compareTo(lhs.getDateLong()));
// Only show changelogs for current and past versions
boolean currentVersionReached = false;
ArrayList<String> versions = new ArrayList<>();
ArrayList<String> dates = new ArrayList<>();
ArrayList<String> changelists = new ArrayList<>();
for (ChangeModel change : changes) {
if (change.getVersion().equals(BuildConfig.VERSION_NAME)) {
currentVersionReached = true;
}
if (currentVersionReached) {
versions.add(change.getVersion());
dates.add(change.getDate());
String changelist = "";
for (int i = 0; i < change.getChanges().size(); i++) {
String changeItem = change.getChanges().get(i);
changelist += " • ";
changelist += changeItem;
if (i < change.getChanges().size() - 1) {
changelist += "\n";
}
}
changelists.add(changelist);
}
}
context.hideProgressDialog();
new QKDialog().setContext(context).setTitle(R.string.title_changelog).setTripleLineItems(versions.toArray(new String[versions.size()]), dates.toArray(new String[versions.size()]), changelists.toArray(new String[versions.size()]), null).show();
}, error -> {
context.hideProgressDialog();
context.makeToast(R.string.toast_changelog_error);
});
context.getRequestQueue().add(request);
}
use of com.moez.QKSMS.ui.dialog.QKDialog in project qksms by moezbhatti.
the class DialogHelper method showDeleteConversationsDialog.
public static void showDeleteConversationsDialog(final QKActivity context, final Set<Long> threadIds) {
new DefaultSmsHelper(context, R.string.not_default_delete).showIfNotDefault(null);
// Make a copy so the list isn't reset when multi-select is disabled
Set<Long> threads = new HashSet<>(threadIds);
new QKDialog().setContext(context).setTitle(R.string.delete_conversation).setMessage(context.getString(R.string.delete_confirmation, threads.size())).setPositiveButton(R.string.yes, v -> {
Log.d(TAG, "Deleting threads: " + Arrays.toString(threads.toArray()));
Conversation.ConversationQueryHandler handler = new Conversation.ConversationQueryHandler(context.getContentResolver(), context);
Conversation.startDelete(handler, 0, false, threads);
Conversation.asyncDeleteObsoleteThreads(handler, 0);
if (context instanceof MessageListActivity) {
context.onBackPressed();
}
}).setNegativeButton(R.string.cancel, null).show();
}
use of com.moez.QKSMS.ui.dialog.QKDialog in project qksms by moezbhatti.
the class DonationManager method showDonateDialog.
public void showDonateDialog() {
View.OnClickListener clickListener = view -> {
switch(view.getId()) {
case R.id.donate_1:
onDonateButtonClicked(SKU_DONATE_1);
break;
case R.id.donate_5:
onDonateButtonClicked(SKU_DONATE_5);
break;
case R.id.donate_10:
onDonateButtonClicked(SKU_DONATE_10);
break;
case R.id.donate_paypal:
donatePaypal();
break;
}
};
View view = mContext.getLayoutInflater().inflate(R.layout.dialog_donate, null);
view.findViewById(R.id.donate_1).setOnClickListener(clickListener);
view.findViewById(R.id.donate_5).setOnClickListener(clickListener);
view.findViewById(R.id.donate_10).setOnClickListener(clickListener);
view.findViewById(R.id.donate_paypal).setOnClickListener(clickListener);
LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> {
view.findViewById(R.id.donate_1).setBackgroundDrawable(ThemeManager.getRippleBackground());
view.findViewById(R.id.donate_5).setBackgroundDrawable(ThemeManager.getRippleBackground());
view.findViewById(R.id.donate_10).setBackgroundDrawable(ThemeManager.getRippleBackground());
view.findViewById(R.id.donate_paypal).setBackgroundDrawable(ThemeManager.getRippleBackground());
});
QKDialog dialog = new QKDialog().setContext(mContext).setCustomView(view);
dialog.show();
}
use of com.moez.QKSMS.ui.dialog.QKDialog in project qksms by moezbhatti.
the class ThemeManager method showColorPicker.
private static void showColorPicker(QKActivity context, View.OnClickListener saveListener) {
final QKDialog dialog = new QKDialog();
View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_color_picker, null, false);
ColorPickerViewHolder holder = new ColorPickerViewHolder(view);
holder.mTab1.setBackgroundDrawable(getRippleBackground());
holder.mTab2.setBackgroundDrawable(getRippleBackground());
holder.mTab1.setOnClickListener(v -> holder.mPager.setCurrentItem(0));
holder.mTab2.setOnClickListener(v -> holder.mPager.setCurrentItem(1));
ColorPickerPagerAdapter adapter = new ColorPickerPagerAdapter(context);
holder.mPager.setAdapter(adapter);
holder.mPager.setOffscreenPageLimit(1);
holder.mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
holder.mTab1.setTextColor(position == 0 ? getColor() : getTextOnBackgroundPrimary());
holder.mTab2.setTextColor(position == 1 ? getColor() : getTextOnBackgroundPrimary());
}
});
int swatchColor = getSwatchColor(getColor());
holder.mPalette.init(19, 4, color -> {
holder.mPalette.init(getSwatch(color).length, 4, color2 -> {
setActiveColor(color2);
saveListener.onClick(null);
dialog.dismiss();
});
holder.mPalette.drawPalette(getSwatch(color), getColor());
});
holder.mPalette.drawPalette(PALETTE, swatchColor);
if (swatchColor == getColor()) {
// If the current theme was set from the RGB picker, show that page instead
holder.mPager.setCurrentItem(1);
}
SeekBar.OnSeekBarChangeListener seekListener = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int color = getColor();
color = Color.rgb(seekBar == holder.mRed ? progress : Color.red(color), seekBar == holder.mGreen ? progress : Color.green(color), seekBar == holder.mBlue ? progress : Color.blue(color));
if (seekBar == holder.mRed)
holder.mRedValue.setText(String.valueOf(progress));
if (seekBar == holder.mGreen)
holder.mGreenValue.setText(String.valueOf(progress));
if (seekBar == holder.mBlue)
holder.mBlueValue.setText(String.valueOf(progress));
setActiveColor(color);
String colorString = Integer.toHexString(color);
holder.mHex.setTextChangedListenerEnabled(false);
holder.mHex.setText(colorString.substring(colorString.length() > 6 ? colorString.length() - 6 : 0));
holder.mHex.setTextChangedListenerEnabled(true);
holder.mError.setVisibility(View.INVISIBLE);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
};
Drawable thumbRed = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
Drawable thumbGreen = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
Drawable thumbBlue = ContextCompat.getDrawable(mContext, R.drawable.seek_thumb);
LiveViewManager.registerView(QKPreference.THEME, holder.mPreview, key -> {
holder.mPreview.setBackgroundColor(getColor());
holder.mRed.getProgressDrawable().setColorFilter(getColor(), PorterDuff.Mode.MULTIPLY);
holder.mGreen.getProgressDrawable().setColorFilter(getColor(), PorterDuff.Mode.MULTIPLY);
holder.mBlue.getProgressDrawable().setColorFilter(getColor(), PorterDuff.Mode.MULTIPLY);
if (holder.mPager.getCurrentItem() == 0) {
holder.mTab1.setTextColor(getColor());
} else {
holder.mTab2.setTextColor(getColor());
}
});
LiveViewManager.registerView(QKPreference.BACKGROUND, holder.mHex, key -> {
holder.mHex.getBackground().setColorFilter(0x22888888, PorterDuff.Mode.MULTIPLY);
holder.mError.setColorFilter(getTextOnBackgroundSecondary(), PorterDuff.Mode.SRC_ATOP);
});
holder.mRed.setThumb(thumbRed);
holder.mRed.setOnSeekBarChangeListener(seekListener);
holder.mGreen.setThumb(thumbGreen);
holder.mGreen.setOnSeekBarChangeListener(seekListener);
holder.mBlue.setThumb(thumbBlue);
holder.mBlue.setOnSeekBarChangeListener(seekListener);
holder.mRed.setProgress(Color.red(getColor()));
holder.mGreen.setProgress(Color.green(getColor()));
holder.mBlue.setProgress(Color.blue(getColor()));
String colorString = Integer.toHexString(getColor());
holder.mHex.setText(colorString.substring(colorString.length() > 6 ? colorString.length() - 6 : 0));
holder.mHex.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
holder.mHex.clearFocus();
KeyboardUtils.hide(mContext, holder.mHex);
}
return false;
});
holder.mHex.setTextChangedListener(s -> {
if (s.length() == 6) {
int color = Color.parseColor("#" + s.toString());
holder.mError.setVisibility(View.INVISIBLE);
if (color != getColor()) {
holder.mRed.setProgress(Color.red(color));
holder.mGreen.setProgress(Color.green(color));
holder.mBlue.setProgress(Color.blue(color));
}
} else {
holder.mError.setVisibility(View.VISIBLE);
}
});
dialog.setContext(context).setCustomView(view).setNegativeButton(R.string.cancel, v -> setActiveColor(getThemeColor())).setPositiveButton(R.string.save, saveListener).show();
}
use of com.moez.QKSMS.ui.dialog.QKDialog in project qksms by moezbhatti.
the class ThemeManager method setIcon.
public static void setIcon(final QKActivity context) {
String[] colors = { "Default", "Dark", "Red", "Pink", "Purple", "DeepPurple", "Indigo", "Blue", "LightBlue", "Cyan", "Teal", "Green", "LightGreen", "Lime", "Yellow", "Amber", "Orange", "DeepOrange", "Brown", "Grey", "BlueGrey" };
RecyclerView recyclerView = new RecyclerView(context);
recyclerView.setLayoutParams(new LinearLayout.LayoutParams(-1, Units.dpToPx(context, 200)));
recyclerView.setLayoutManager(new GridLayoutManager(context, 4));
recyclerView.setAdapter(new IconAdapter(context, (parent, view, position, id) -> {
PackageManager packageManager = context.getPackageManager();
// Disable all of the color aliases, except for the alias with the current
// color.
String enabledComponent = null;
for (int i = 0; i < colors.length; i++) {
String componentClassName = String.format("com.moez.QKSMS.ui.MainActivity-%s", colors[i]);
// it's all done.
if (i == position) {
enabledComponent = componentClassName;
} else {
packageManager.setComponentEnabledSetting(new ComponentName(context, componentClassName), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, // won't show up to the user.
PackageManager.DONT_KILL_APP);
}
}
// Broadcast an intent to a receiver that will:
// 1) enable the last component; and
// 2) relaunch QKSMS with the new component name.
Intent intent = new Intent(IconColorReceiver.ACTION_ICON_COLOR_CHANGED);
intent.putExtra(IconColorReceiver.EXTRA_COMPONENT_NAME, enabledComponent);
context.sendBroadcast(intent);
}));
new QKDialog().setContext(context).setTitle(R.string.update_icon_title).setMessage(R.string.update_icon_message).setCustomView(recyclerView).setNegativeButton(R.string.cancel, null).show();
}
Aggregations