package com.google.android.libraries.places.internal; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import androidx.lifecycle.LiveData; import com.google.android.gms.common.api.ApiException; import com.google.android.gms.common.api.Status; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.android.libraries.places.api.model.AutocompletePrediction; import com.google.android.libraries.places.api.net.FetchPlaceResponse; import com.google.android.libraries.places.api.net.FindAutocompletePredictionsResponse; import java.util.List; import o.HeN; import o.VKL; /* loaded from: classes2.dex */ public final class zzhl extends VKL { private final zzgy zza; private final zzho zzb; private final zzhp zzc; private Runnable zze; private final Handler zzd = new Handler(Looper.getMainLooper()); private final HeN zzf = new HeN(); /* JADX INFO: Access modifiers changed from: package-private */ public /* synthetic */ zzhl(zzgy zzgyVar, zzho zzhoVar, zzhp zzhpVar, zzhk zzhkVar) { this.zza = zzgyVar; this.zzb = zzhoVar; this.zzc = zzhpVar; } private static Status zzn(Exception exc) { if (exc instanceof ApiException) { return ((ApiException) exc).getStatus(); } return new Status(13, exc.getMessage()); } private static boolean zzp(Status status) { return status.isCanceled() || status.getStatusCode() == 9012 || status.getStatusCode() == 9011; } @Override // o.VKL public final void onCleared() { try { this.zza.zzc(); this.zzd.removeCallbacks(this.zze); this.zzb.zzo(); this.zzc.zza(this.zzb); } catch (Error | RuntimeException e) { zzgb.zzb(e); throw e; } } /* JADX INFO: Access modifiers changed from: package-private */ public final /* synthetic */ void zzb(String str, Task task) { if (task.isCanceled()) { return; } Exception exception = task.getException(); if (exception == null) { this.zzb.zzp(); List autocompletePredictions = ((FindAutocompletePredictionsResponse) task.getResult()).getAutocompletePredictions(); if (autocompletePredictions.isEmpty()) { zzo(zzgt.zzh(str)); return; } else { zzo(zzgt.zzj(autocompletePredictions)); return; } } this.zzb.zzr(); Status zzn = zzn(exception); if (zzp(zzn)) { zzo(zzgt.zzq(zzn)); } else { zzo(zzgt.zzi(str, zzn)); } } /* JADX INFO: Access modifiers changed from: package-private */ public final /* synthetic */ void zzc(AutocompletePrediction autocompletePrediction, Task task) { if (task.isCanceled()) { return; } Exception exception = task.getException(); if (exception == null) { this.zzb.zzq(); zzo(zzgt.zzn(((FetchPlaceResponse) task.getResult()).getPlace())); return; } this.zzb.zzs(); Status zzn = zzn(exception); if (zzp(zzn)) { zzo(zzgt.zzq(zzn)); } else { zzo(zzgt.zzm(autocompletePrediction, zzn)); } } /* JADX INFO: Access modifiers changed from: package-private */ public final /* synthetic */ void zzd(final String str) { this.zza.zzb(str).addOnCompleteListener(new OnCompleteListener(this, str) { // from class: com.google.android.libraries.places.internal.zzhh public final zzhl zza; public final String zzb; @Override // com.google.android.gms.tasks.OnCompleteListener public final void onComplete(Task task) { this.zza.zzb(this.zzb, task); } { this.zza = this; this.zzb = str; } }); } public final void zze(Bundle bundle) { if (bundle == null) { this.zzf.a((HeN) zzgt.zzo()); } } public final void zzf(final AutocompletePrediction autocompletePrediction, int i) { this.zzb.zzu(i); Task zza = this.zza.zza(autocompletePrediction); if (!zza.isComplete()) { zzo(zzgt.zzg()); } zza.addOnCompleteListener(new OnCompleteListener(this, autocompletePrediction) { // from class: com.google.android.libraries.places.internal.zzhg public final zzhl zza; public final AutocompletePrediction zzb; @Override // com.google.android.gms.tasks.OnCompleteListener public final void onComplete(Task task) { this.zza.zzc(this.zzb, task); } { this.zza = this; this.zzb = autocompletePrediction; } }); } public final void zzg() { this.zzb.zzv(); } public final void zzh() { this.zzb.zzl(); } public final void zzi() { this.zzb.zzm(); } public final void zzj() { this.zzb.zzn(); zzo(zzgt.zzl()); } public final void zzk() { this.zzb.zzw(); zzm(""); } public final void zzl(String str) { this.zza.zzc(); zzm(str); zzo(zzgt.zzp()); } public final void zzm(final String str) { this.zzb.zzt(str); this.zzd.removeCallbacks(this.zze); if (str.isEmpty()) { this.zza.zzc(); zzo(zzgt.zzk()); } else { Runnable runnable = new Runnable(this, str) { // from class: com.google.android.libraries.places.internal.zzhi public final zzhl zza; public final String zzb; @Override // java.lang.Runnable public final void run() { this.zza.zzd(this.zzb); } { this.zza = this; this.zzb = str; } }; this.zze = runnable; this.zzd.postDelayed(runnable, 100L); zzo(zzgt.zzg()); } } private final void zzo(zzgt zzgtVar) { Object obj = this.zzf.d; if (obj == LiveData.c) { obj = null; } if (zzgtVar.equals(obj)) { return; } this.zzf.a((HeN) zzgtVar); } public final LiveData zza() { return this.zzf; } }