Search in sources :

Example 6 with QKDialog

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);
}
Also used : StringRequest(com.android.volley.toolbox.StringRequest) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Date(java.util.Date) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) ChangeModel(com.moez.QKSMS.model.ChangeModel) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with QKDialog

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();
}
Also used : MessageListActivity(com.moez.QKSMS.ui.messagelist.MessageListActivity) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) DefaultSmsHelper(com.moez.QKSMS.ui.dialog.DefaultSmsHelper) Conversation(com.moez.QKSMS.data.Conversation) HashSet(java.util.HashSet)

Example 8 with QKDialog

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();
}
Also used : QKPreference(com.moez.QKSMS.enums.QKPreference) IabResult(com.moez.QKSMS.external.iab.IabResult) ThemeManager(com.moez.QKSMS.ui.ThemeManager) Uri(android.net.Uri) Intent(android.content.Intent) Random(java.util.Random) IabHelper(com.moez.QKSMS.external.iab.IabHelper) QKActivity(com.moez.QKSMS.ui.base.QKActivity) R(com.moez.QKSMS.R) Purchase(com.moez.QKSMS.external.iab.Purchase) Toast(android.widget.Toast) View(android.view.View) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) Log(android.util.Log) Resources(android.content.res.Resources) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) View(android.view.View)

Example 9 with QKDialog

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();
}
Also used : SeekBar(android.widget.SeekBar) Drawable(android.graphics.drawable.Drawable) QKTextView(com.moez.QKSMS.ui.view.QKTextView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ViewPager(android.support.v4.view.ViewPager) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) ColorPickerPagerAdapter(com.moez.QKSMS.ui.dialog.ColorPickerPagerAdapter)

Example 10 with QKDialog

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();
}
Also used : ColorPickerPalette(com.moez.QKSMS.ui.view.colorpicker.ColorPickerPalette) GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) QKTextView(com.moez.QKSMS.ui.view.QKTextView) ImageView(android.widget.ImageView) Animator(android.animation.Animator) WidgetProvider(com.moez.QKSMS.ui.widget.WidgetProvider) Drawable(android.graphics.drawable.Drawable) LiveViewManager(com.moez.QKSMS.common.LiveViewManager) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) Bind(butterknife.Bind) PreferenceManager(android.preference.PreferenceManager) TargetApi(android.annotation.TargetApi) Log(android.util.Log) ContextCompat(android.support.v4.content.ContextCompat) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) AnalyticsManager(com.moez.QKSMS.common.AnalyticsManager) ColorUtils(com.moez.QKSMS.common.utils.ColorUtils) IconColorReceiver(com.moez.QKSMS.receiver.IconColorReceiver) Units(com.moez.QKSMS.common.utils.Units) SettingsFragment(com.moez.QKSMS.ui.settings.SettingsFragment) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Context(android.content.Context) QKPreference(com.moez.QKSMS.enums.QKPreference) ButterKnife(butterknife.ButterKnife) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) QKActivity(com.moez.QKSMS.ui.base.QKActivity) KeyboardUtils(com.moez.QKSMS.common.utils.KeyboardUtils) R(com.moez.QKSMS.R) SeekBar(android.widget.SeekBar) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) ColorPickerPagerAdapter(com.moez.QKSMS.ui.dialog.ColorPickerPagerAdapter) Build(android.os.Build) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) QKEditText(com.moez.QKSMS.ui.view.QKEditText) CIELChEvaluator(com.moez.QKSMS.common.CIELChEvaluator) Color(android.graphics.Color) ColorInt(android.support.annotation.ColorInt) IconAdapter(com.moez.QKSMS.theme.IconAdapter) RecyclerView(android.support.v7.widget.RecyclerView) DrawableRes(android.support.annotation.DrawableRes) SharedPreferences(android.content.SharedPreferences) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper) ValueAnimator(android.animation.ValueAnimator) Resources(android.content.res.Resources) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) GridLayoutManager(android.support.v7.widget.GridLayoutManager) PackageManager(android.content.pm.PackageManager) IconAdapter(com.moez.QKSMS.theme.IconAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ComponentName(android.content.ComponentName) Intent(android.content.Intent) LinearLayout(android.widget.LinearLayout)

Aggregations

QKDialog (com.moez.QKSMS.ui.dialog.QKDialog)15 View (android.view.View)7 QKTextView (com.moez.QKSMS.ui.view.QKTextView)5 Intent (android.content.Intent)4 Log (android.util.Log)4 R (com.moez.QKSMS.R)4 QKPreference (com.moez.QKSMS.enums.QKPreference)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Context (android.content.Context)3 Uri (android.net.Uri)3 AdapterView (android.widget.AdapterView)3 ImageView (android.widget.ImageView)3 ParseException (java.text.ParseException)3 SharedPreferences (android.content.SharedPreferences)2 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 Drawable (android.graphics.drawable.Drawable)2 Bundle (android.os.Bundle)2 CheckBoxPreference (android.preference.CheckBoxPreference)2