Search in sources :

Example 1 with BetterRatingView

use of org.telegram.ui.Components.BetterRatingView in project Telegram-FOSS by Telegram-FOSS-Team.

the class VoIPHelper method showRateAlert.

public static void showRateAlert(final Context context, final Runnable onDismiss, boolean isVideo, final long callID, final long accessHash, final int account, final boolean userInitiative) {
    final File log = getLogFile(callID);
    final int[] page = { 0 };
    LinearLayout alertView = new LinearLayout(context);
    alertView.setOrientation(LinearLayout.VERTICAL);
    int pad = AndroidUtilities.dp(16);
    alertView.setPadding(pad, pad, pad, 0);
    TextView text = new TextView(context);
    text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    text.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    text.setGravity(Gravity.CENTER);
    text.setText(LocaleController.getString("VoipRateCallAlert", R.string.VoipRateCallAlert));
    alertView.addView(text);
    final BetterRatingView bar = new BetterRatingView(context);
    alertView.addView(bar, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 16, 0, 0));
    final LinearLayout problemsWrap = new LinearLayout(context);
    problemsWrap.setOrientation(LinearLayout.VERTICAL);
    View.OnClickListener problemCheckboxClickListener = v -> {
        CheckBoxCell check = (CheckBoxCell) v;
        check.setChecked(!check.isChecked(), true);
    };
    final String[] problems = { isVideo ? "distorted_video" : null, isVideo ? "pixelated_video" : null, "echo", "noise", "interruptions", "distorted_speech", "silent_local", "silent_remote", "dropped" };
    for (int i = 0; i < problems.length; i++) {
        if (problems[i] == null) {
            continue;
        }
        CheckBoxCell check = new CheckBoxCell(context, 1);
        check.setClipToPadding(false);
        check.setTag(problems[i]);
        String label = null;
        switch(i) {
            case 0:
                label = LocaleController.getString("RateCallVideoDistorted", R.string.RateCallVideoDistorted);
                break;
            case 1:
                label = LocaleController.getString("RateCallVideoPixelated", R.string.RateCallVideoPixelated);
                break;
            case 2:
                label = LocaleController.getString("RateCallEcho", R.string.RateCallEcho);
                break;
            case 3:
                label = LocaleController.getString("RateCallNoise", R.string.RateCallNoise);
                break;
            case 4:
                label = LocaleController.getString("RateCallInterruptions", R.string.RateCallInterruptions);
                break;
            case 5:
                label = LocaleController.getString("RateCallDistorted", R.string.RateCallDistorted);
                break;
            case 6:
                label = LocaleController.getString("RateCallSilentLocal", R.string.RateCallSilentLocal);
                break;
            case 7:
                label = LocaleController.getString("RateCallSilentRemote", R.string.RateCallSilentRemote);
                break;
            case 8:
                label = LocaleController.getString("RateCallDropped", R.string.RateCallDropped);
                break;
        }
        check.setText(label, null, false, false);
        check.setOnClickListener(problemCheckboxClickListener);
        check.setTag(problems[i]);
        problemsWrap.addView(check);
    }
    alertView.addView(problemsWrap, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, -8, 0, -8, 0));
    problemsWrap.setVisibility(View.GONE);
    final EditTextBoldCursor commentBox = new EditTextBoldCursor(context);
    commentBox.setHint(LocaleController.getString("VoipFeedbackCommentHint", R.string.VoipFeedbackCommentHint));
    commentBox.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    commentBox.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    commentBox.setHintTextColor(Theme.getColor(Theme.key_dialogTextHint));
    commentBox.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));
    commentBox.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4));
    commentBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    commentBox.setVisibility(View.GONE);
    alertView.addView(commentBox, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 8, 8, 8, 0));
    final boolean[] includeLogs = { true };
    final CheckBoxCell checkbox = new CheckBoxCell(context, 1);
    View.OnClickListener checkClickListener = v -> {
        includeLogs[0] = !includeLogs[0];
        checkbox.setChecked(includeLogs[0], true);
    };
    checkbox.setText(LocaleController.getString("CallReportIncludeLogs", R.string.CallReportIncludeLogs), null, true, false);
    checkbox.setClipToPadding(false);
    checkbox.setOnClickListener(checkClickListener);
    alertView.addView(checkbox, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, -8, 0, -8, 0));
    final TextView logsText = new TextView(context);
    logsText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
    logsText.setTextColor(Theme.getColor(Theme.key_dialogTextGray3));
    logsText.setText(LocaleController.getString("CallReportLogsExplain", R.string.CallReportLogsExplain));
    logsText.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
    logsText.setOnClickListener(checkClickListener);
    alertView.addView(logsText);
    checkbox.setVisibility(View.GONE);
    logsText.setVisibility(View.GONE);
    if (!log.exists()) {
        includeLogs[0] = false;
    }
    final AlertDialog alert = new AlertDialog.Builder(context).setTitle(LocaleController.getString("CallMessageReportProblem", R.string.CallMessageReportProblem)).setView(alertView).setPositiveButton(LocaleController.getString("Send", R.string.Send), (dialog, which) -> {
    // SendMessagesHelper.getInstance(currentAccount).sendMessage(commentBox.getText().toString(), VOIP_SUPPORT_ID, null, null, true, null, null, null);
    }).setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null).setOnDismissListener(dialog -> {
        if (onDismiss != null)
            onDismiss.run();
    }).create();
    if (BuildVars.LOGS_ENABLED && log.exists()) {
        alert.setNeutralButton("Send log", (dialog, which) -> {
            Intent intent = new Intent(context, LaunchActivity.class);
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(log));
            context.startActivity(intent);
        });
    }
    alert.show();
    alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    final View btn = alert.getButton(DialogInterface.BUTTON_POSITIVE);
    btn.setEnabled(false);
    bar.setOnRatingChangeListener(rating -> {
        btn.setEnabled(rating > 0);
        /*commentBox.setHint(rating<4 ? LocaleController.getString("CallReportHint", R.string.CallReportHint) : LocaleController.getString("VoipFeedbackCommentHint", R.string.VoipFeedbackCommentHint));
			commentBox.setVisibility(rating < 5 && rating > 0 ? View.VISIBLE : View.GONE);
			if (commentBox.getVisibility() == View.GONE) {
				((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(commentBox.getWindowToken(), 0);
			}
			*/
        ((TextView) btn).setText((rating < 4 ? LocaleController.getString("Next", R.string.Next) : LocaleController.getString("Send", R.string.Send)).toUpperCase());
    });
    btn.setOnClickListener(v -> {
        int rating = bar.getRating();
        if (rating >= 4 || page[0] == 1) {
            final int currentAccount = UserConfig.selectedAccount;
            final TLRPC.TL_phone_setCallRating req = new TLRPC.TL_phone_setCallRating();
            req.rating = bar.getRating();
            ArrayList<String> problemTags = new ArrayList<>();
            for (int i = 0; i < problemsWrap.getChildCount(); i++) {
                CheckBoxCell check = (CheckBoxCell) problemsWrap.getChildAt(i);
                if (check.isChecked())
                    problemTags.add("#" + check.getTag());
            }
            if (req.rating < 5) {
                req.comment = commentBox.getText().toString();
            } else {
                req.comment = "";
            }
            if (!problemTags.isEmpty() && !includeLogs[0]) {
                req.comment += " " + TextUtils.join(" ", problemTags);
            }
            req.peer = new TLRPC.TL_inputPhoneCall();
            req.peer.access_hash = accessHash;
            req.peer.id = callID;
            req.user_initiative = userInitiative;
            ConnectionsManager.getInstance(account).sendRequest(req, (response, error) -> {
                if (response instanceof TLRPC.TL_updates) {
                    TLRPC.TL_updates updates = (TLRPC.TL_updates) response;
                    MessagesController.getInstance(currentAccount).processUpdates(updates, false);
                }
                if (includeLogs[0] && log.exists() && req.rating < 4) {
                    AccountInstance accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount);
                    SendMessagesHelper.prepareSendingDocument(accountInstance, log.getAbsolutePath(), log.getAbsolutePath(), null, TextUtils.join(" ", problemTags), "text/plain", VOIP_SUPPORT_ID, null, null, null, null, true, 0);
                    Toast.makeText(context, LocaleController.getString("CallReportSent", R.string.CallReportSent), Toast.LENGTH_LONG).show();
                }
            });
            alert.dismiss();
        } else {
            page[0] = 1;
            bar.setVisibility(View.GONE);
            // text.setText(LocaleController.getString("CallReportHint", R.string.CallReportHint));
            text.setVisibility(View.GONE);
            alert.setTitle(LocaleController.getString("CallReportHint", R.string.CallReportHint));
            commentBox.setVisibility(View.VISIBLE);
            if (log.exists()) {
                checkbox.setVisibility(View.VISIBLE);
                logsText.setVisibility(View.VISIBLE);
            }
            problemsWrap.setVisibility(View.VISIBLE);
            ((TextView) btn).setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
        }
    });
}
Also used : LinearLayout(android.widget.LinearLayout) Arrays(java.util.Arrays) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) BetterRatingView(org.telegram.ui.Components.BetterRatingView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) JoinCallByUrlAlert(org.telegram.ui.Components.JoinCallByUrlAlert) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) Manifest(android.Manifest) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) View(android.view.View) TargetApi(android.annotation.TargetApi) InputType(android.text.InputType) Set(java.util.Set) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) Instance(org.telegram.messenger.voip.Instance) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) GroupCallActivity(org.telegram.ui.GroupCallActivity) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) LaunchActivity(org.telegram.ui.LaunchActivity) Context(android.content.Context) VoIPService(org.telegram.messenger.voip.VoIPService) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) SystemClock(android.os.SystemClock) LocaleController(org.telegram.messenger.LocaleController) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) Settings(android.provider.Settings) MessageObject(org.telegram.messenger.MessageObject) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) DownloadController(org.telegram.messenger.DownloadController) DialogInterface(android.content.DialogInterface) R(org.telegram.messenger.R) JoinCallAlert(org.telegram.ui.Components.JoinCallAlert) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) File(java.io.File) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) TextView(android.widget.TextView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Intent(android.content.Intent) BetterRatingView(org.telegram.ui.Components.BetterRatingView) View(android.view.View) TextView(android.widget.TextView) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) AccountInstance(org.telegram.messenger.AccountInstance) File(java.io.File) LinearLayout(android.widget.LinearLayout) BetterRatingView(org.telegram.ui.Components.BetterRatingView)

Aggregations

Manifest (android.Manifest)1 TargetApi (android.annotation.TargetApi)1 Activity (android.app.Activity)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 Build (android.os.Build)1 SystemClock (android.os.SystemClock)1 Settings (android.provider.Settings)1 InputType (android.text.InputType)1 TextUtils (android.text.TextUtils)1 TypedValue (android.util.TypedValue)1 Gravity (android.view.Gravity)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1