导航菜单

页面标题

页面副标题

Biko v2.0.23 - UserRegistrationActivity.java 源代码

正在查看: Biko v2.0.23 应用的 UserRegistrationActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package app.callpe.ui.user;

import android.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import androidx.activity.ComponentActivity;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleOwnerKt;
import androidx.lifecycle.ViewModelLazy;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStore;
import androidx.lifecycle.viewmodel.CreationExtras;
import app.callpe.common.utils.DateHelper;
import app.callpe.common.utils.extensions.ActivityExtKt;
import app.callpe.common.utils.extensions.EdittextExtKt;
import app.callpe.common.utils.extensions.ViewExtKt;
import app.callpe.common.utils.helper_functions.EmojiFilter;
import app.callpe.common.utils.helper_functions.OnlyAlphabetsFilter;
import app.callpe.data.model.User;
import app.callpe.data.model.UserDetailBody;
import app.callpe.databinding.ActivityUserRegistrationBinding;
import app.callpe.service.FirebaseNotificationService;
import app.callpe.ui.SplashActivity;
import com.google.gson.Gson;
import dagger.hilt.android.AndroidEntryPoint;
import java.util.Date;
import kotlin.Lazy;
import kotlin.Metadata;
import kotlin.coroutines.CoroutineContext;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Reflection;
import kotlin.text.StringsKt;
import kotlinx.coroutines.BuildersKt;
import kotlinx.coroutines.CoroutineStart;
import kotlinx.coroutines.Job;
import timber.log.Timber;

@Metadata(d1 = {"\u00002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0007\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\b\u0010\u000b\u001a\u00020\fH\u0002J\b\u0010\r\u001a\u00020\fH\u0002J\b\u0010\u000e\u001a\u00020\fH\u0002J\b\u0010\u000f\u001a\u00020\u0010H\u0002J\b\u0010\u0011\u001a\u00020\fH\u0002J\u0012\u0010\u0012\u001a\u00020\f2\b\u0010\u0013\u001a\u0004\u0018\u00010\u0014H\u0014J\b\u0010\u0015\u001a\u00020\fH\u0002J\b\u0010\u0016\u001a\u00020\fH\u0002J\b\u0010\u0017\u001a\u00020\fH\u0002J\b\u0010\u0018\u001a\u00020\fH\u0002J\b\u0010\u0019\u001a\u00020\fH\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082.¢\u0006\u0002\n\u0000R\u001b\u0010\u0005\u001a\u00020\u00068BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b\t\u0010\n\u001a\u0004\b\u0007\u0010\b¨\u0006\u001a"}, d2 = {"Lapp/callpe/ui/user/UserRegistrationActivity;", "Landroidx/appcompat/app/AppCompatActivity;", "()V", "binding", "Lapp/callpe/databinding/ActivityUserRegistrationBinding;", "viewModel", "Lapp/callpe/ui/user/UserViewModel;", "getViewModel", "()Lapp/callpe/ui/user/UserViewModel;", "viewModel$delegate", "Lkotlin/Lazy;", "getUser", "", "goToSplashActivity", "observeEditText", "observeEvent", "Lkotlinx/coroutines/Job;", "onClick", "onCreate", "savedInstanceState", "Landroid/os/Bundle;", "onFemaleSelected", "onMaleSelected", "refresh", "save", "setValues", "app_bikoRelease"}, k = 1, mv = {1, 8, 0}, xi = 48)
@AndroidEntryPoint
public final class UserRegistrationActivity extends Hilt_UserRegistrationActivity {
    private ActivityUserRegistrationBinding binding;

    private final Lazy viewModel;

    public UserRegistrationActivity() {
        final ComponentActivity componentActivity = (ComponentActivity) this;
        final Function0 function0 = null;
        this.viewModel = new ViewModelLazy(Reflection.getOrCreateKotlinClass(UserViewModel.class), new Function0<ViewModelStore>() {
            {
                super(0);
            }

            public final ViewModelStore m2310invoke() {
                return componentActivity.getViewModelStore();
            }
        }, new Function0<ViewModelProvider.Factory>() {
            {
                super(0);
            }

            public final ViewModelProvider.Factory m2309invoke() {
                return componentActivity.getDefaultViewModelProviderFactory();
            }
        }, new Function0<CreationExtras>() {
            {
                super(0);
            }

            public final CreationExtras m2311invoke() {
                CreationExtras creationExtras;
                Function0 function02 = function0;
                return (function02 == null || (creationExtras = (CreationExtras) function02.invoke()) == null) ? componentActivity.getDefaultViewModelCreationExtras() : creationExtras;
            }
        });
    }

    public final UserViewModel getViewModel() {
        return (UserViewModel) this.viewModel.getValue();
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityUserRegistrationBinding inflate = ActivityUserRegistrationBinding.inflate(getLayoutInflater());
        Intrinsics.checkNotNullExpressionValue(inflate, "inflate(layoutInflater)");
        this.binding = inflate;
        if (inflate == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            inflate = null;
        }
        setContentView((View) inflate.getRoot());
        onClick();
        observeEditText();
        observeEvent();
        getUser();
        setValues();
        getViewModel().getUserDetails(true);
    }

    private final void setValues() {
        ActivityUserRegistrationBinding activityUserRegistrationBinding = this.binding;
        ActivityUserRegistrationBinding activityUserRegistrationBinding2 = null;
        if (activityUserRegistrationBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding = null;
        }
        activityUserRegistrationBinding.userName.setFilters(new InputFilter[]{new OnlyAlphabetsFilter(), new InputFilter.LengthFilter(20), new EmojiFilter()});
        ActivityUserRegistrationBinding activityUserRegistrationBinding3 = this.binding;
        if (activityUserRegistrationBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding3 = null;
        }
        EditText editText = activityUserRegistrationBinding3.userName;
        Intrinsics.checkNotNullExpressionValue(editText, "binding.userName");
        EdittextExtKt.disablePaste(editText);
        ActivityUserRegistrationBinding activityUserRegistrationBinding4 = this.binding;
        if (activityUserRegistrationBinding4 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
        } else {
            activityUserRegistrationBinding2 = activityUserRegistrationBinding4;
        }
        activityUserRegistrationBinding2.userName.requestFocus();
    }

    private final Job observeEvent() {
        return BuildersKt.launch$default(LifecycleOwnerKt.getLifecycleScope((LifecycleOwner) this), (CoroutineContext) null, (CoroutineStart) null, new UserRegistrationActivity$observeEvent$1(this, null), 3, (Object) null);
    }

    private final void getUser() {
        User user;
        String stringExtra = getIntent().getStringExtra("user");
        String str = stringExtra;
        if ((str == null || str.length() == 0) || (user = (User) new Gson().fromJson(stringExtra, User.class)) == null) {
            return;
        }
        getViewModel().setUser(user);
        ActivityUserRegistrationBinding activityUserRegistrationBinding = this.binding;
        ActivityUserRegistrationBinding activityUserRegistrationBinding2 = null;
        if (activityUserRegistrationBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding = null;
        }
        LinearLayout linearLayout = activityUserRegistrationBinding.dobParent;
        Intrinsics.checkNotNullExpressionValue(linearLayout, "binding.dobParent");
        ViewExtKt.showOrGone(linearLayout, true);
        ActivityUserRegistrationBinding activityUserRegistrationBinding3 = this.binding;
        if (activityUserRegistrationBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
        } else {
            activityUserRegistrationBinding2 = activityUserRegistrationBinding3;
        }
        activityUserRegistrationBinding2.userName.setText(user.getName());
        if (Intrinsics.areEqual(user.getGender(), "MALE")) {
            onMaleSelected();
        } else {
            onFemaleSelected();
        }
    }

    private final void onFemaleSelected() {
        ActivityUserRegistrationBinding activityUserRegistrationBinding = this.binding;
        ActivityUserRegistrationBinding activityUserRegistrationBinding2 = null;
        if (activityUserRegistrationBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding = null;
        }
        activityUserRegistrationBinding.maleRadioBtn.setChecked(false);
        ActivityUserRegistrationBinding activityUserRegistrationBinding3 = this.binding;
        if (activityUserRegistrationBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
        } else {
            activityUserRegistrationBinding2 = activityUserRegistrationBinding3;
        }
        activityUserRegistrationBinding2.femaleRadioBtn.setChecked(true);
    }

    private final void onMaleSelected() {
        ActivityUserRegistrationBinding activityUserRegistrationBinding = this.binding;
        ActivityUserRegistrationBinding activityUserRegistrationBinding2 = null;
        if (activityUserRegistrationBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding = null;
        }
        activityUserRegistrationBinding.maleRadioBtn.setChecked(true);
        ActivityUserRegistrationBinding activityUserRegistrationBinding3 = this.binding;
        if (activityUserRegistrationBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
        } else {
            activityUserRegistrationBinding2 = activityUserRegistrationBinding3;
        }
        activityUserRegistrationBinding2.femaleRadioBtn.setChecked(false);
    }

    private final void observeEditText() {
        ActivityUserRegistrationBinding activityUserRegistrationBinding = this.binding;
        if (activityUserRegistrationBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding = null;
        }
        activityUserRegistrationBinding.userName.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable s) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                ActivityUserRegistrationBinding activityUserRegistrationBinding2;
                ActivityUserRegistrationBinding activityUserRegistrationBinding3;
                activityUserRegistrationBinding2 = UserRegistrationActivity.this.binding;
                ActivityUserRegistrationBinding activityUserRegistrationBinding4 = null;
                if (activityUserRegistrationBinding2 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("binding");
                    activityUserRegistrationBinding2 = null;
                }
                Editable text = activityUserRegistrationBinding2.userName.getText();
                String str = String.valueOf(text != null ? StringsKt.trim(text) : null).length() + " / 20";
                activityUserRegistrationBinding3 = UserRegistrationActivity.this.binding;
                if (activityUserRegistrationBinding3 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("binding");
                } else {
                    activityUserRegistrationBinding4 = activityUserRegistrationBinding3;
                }
                activityUserRegistrationBinding4.nickNameTextCount.setText(str);
            }
        });
    }

    private final void onClick() {
        ActivityUserRegistrationBinding activityUserRegistrationBinding = this.binding;
        ActivityUserRegistrationBinding activityUserRegistrationBinding2 = null;
        if (activityUserRegistrationBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding = null;
        }
        activityUserRegistrationBinding.submitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                UserRegistrationActivity.onClick$lambda$0(UserRegistrationActivity.this, view);
            }
        });
        ActivityUserRegistrationBinding activityUserRegistrationBinding3 = this.binding;
        if (activityUserRegistrationBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding3 = null;
        }
        activityUserRegistrationBinding3.maleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                UserRegistrationActivity.onClick$lambda$1(UserRegistrationActivity.this, view);
            }
        });
        ActivityUserRegistrationBinding activityUserRegistrationBinding4 = this.binding;
        if (activityUserRegistrationBinding4 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
        } else {
            activityUserRegistrationBinding2 = activityUserRegistrationBinding4;
        }
        activityUserRegistrationBinding2.femaleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                UserRegistrationActivity.onClick$lambda$2(UserRegistrationActivity.this, view);
            }
        });
    }

    public static final void onClick$lambda$0(UserRegistrationActivity userRegistrationActivity, View view) {
        Intrinsics.checkNotNullParameter(userRegistrationActivity, "this$0");
        userRegistrationActivity.save();
    }

    public static final void onClick$lambda$1(UserRegistrationActivity userRegistrationActivity, View view) {
        Intrinsics.checkNotNullParameter(userRegistrationActivity, "this$0");
        userRegistrationActivity.onMaleSelected();
    }

    public static final void onClick$lambda$2(UserRegistrationActivity userRegistrationActivity, View view) {
        Intrinsics.checkNotNullParameter(userRegistrationActivity, "this$0");
        userRegistrationActivity.onFemaleSelected();
    }

    private final void refresh() {
        getViewModel().getUserDetails(true);
    }

    private final void save() {
        DateHelper dateHelper = DateHelper.INSTANCE;
        ActivityUserRegistrationBinding activityUserRegistrationBinding = this.binding;
        ActivityUserRegistrationBinding activityUserRegistrationBinding2 = null;
        if (activityUserRegistrationBinding == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding = null;
        }
        Date date = activityUserRegistrationBinding.dobPick.getDate();
        Intrinsics.checkNotNullExpressionValue(date, "binding.dobPick.date");
        String formatDate = dateHelper.formatDate(date, "yyyy-MM-dd");
        ActivityUserRegistrationBinding activityUserRegistrationBinding3 = this.binding;
        if (activityUserRegistrationBinding3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding3 = null;
        }
        Editable text = activityUserRegistrationBinding3.userName.getText();
        if (text == null || text.length() == 0) {
            ActivityExtKt.toast((Activity) this, "Nickname required");
            return;
        }
        ActivityUserRegistrationBinding activityUserRegistrationBinding4 = this.binding;
        if (activityUserRegistrationBinding4 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding4 = null;
        }
        if (!activityUserRegistrationBinding4.femaleRadioBtn.isChecked()) {
            ActivityUserRegistrationBinding activityUserRegistrationBinding5 = this.binding;
            if (activityUserRegistrationBinding5 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("binding");
                activityUserRegistrationBinding5 = null;
            }
            if (!activityUserRegistrationBinding5.maleRadioBtn.isChecked()) {
                ActivityExtKt.toast((Activity) this, "Gender required");
                return;
            }
        }
        if (DateHelper.INSTANCE.isUnderAge(formatDate)) {
            ActivityExtKt.toast((Activity) this, "You must be at least 18 years old.");
            return;
        }
        ActivityUserRegistrationBinding activityUserRegistrationBinding6 = this.binding;
        if (activityUserRegistrationBinding6 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
            activityUserRegistrationBinding6 = null;
        }
        String valueOf = String.valueOf(activityUserRegistrationBinding6.userName.getText());
        ActivityUserRegistrationBinding activityUserRegistrationBinding7 = this.binding;
        if (activityUserRegistrationBinding7 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("binding");
        } else {
            activityUserRegistrationBinding2 = activityUserRegistrationBinding7;
        }
        String str = activityUserRegistrationBinding2.maleRadioBtn.isChecked() ? "MALE" : "FEMALE";
        String token = FirebaseNotificationService.INSTANCE.getToken((Context) this);
        String avatar = getViewModel().getAvatar();
        if (avatar == null) {
            avatar = "https://i.imgur.com/QmMuGvh.png";
        }
        UserDetailBody userDetailBody = new UserDetailBody(formatDate, token, str, valueOf, -1L, avatar, null, null, null, null, null, 1920, null);
        Timber.e(valueOf + ' ' + str + ' ' + formatDate, new Object[0]);
        StringBuilder sb = new StringBuilder();
        sb.append("user ");
        sb.append(userDetailBody);
        Timber.e(sb.toString(), new Object[0]);
        getViewModel().updateProfile(userDetailBody);
    }

    public final void goToSplashActivity() {
        Intent intent = new Intent((Context) this, (Class<?>) SplashActivity.class);
        intent.addFlags(268468224);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    }
}