Accept URLs in instance search

This commit is contained in:
Grishka 2022-05-03 15:35:48 +03:00
parent d4e4d9fcde
commit bbedf46b21
1 changed files with 17 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package org.joinmastodon.android.fragments.onboarding;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.LocaleList; import android.os.LocaleList;
@ -349,7 +350,7 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment<CatalogInstanc
currentSearchQuery=searchEdit.getText().toString().toLowerCase(); currentSearchQuery=searchEdit.getText().toString().toLowerCase();
updateFilteredList(); updateFilteredList();
searchEdit.removeCallbacks(searchDebouncer); searchEdit.removeCallbacks(searchDebouncer);
Instance instance=instancesCache.get(currentSearchQuery); Instance instance=instancesCache.get(normalizeInstanceDomain(currentSearchQuery));
if(instance==null){ if(instance==null){
showProgressDialog(); showProgressDialog();
loadInstanceInfo(currentSearchQuery); loadInstanceInfo(currentSearchQuery);
@ -412,15 +413,27 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment<CatalogInstanc
instanceProgressDialog.show(); instanceProgressDialog.show();
} }
private void loadInstanceInfo(String _domain){ private String normalizeInstanceDomain(String _domain){
if(TextUtils.isEmpty(_domain)) if(TextUtils.isEmpty(_domain))
return; return null;
if(_domain.contains(":")){
try{
_domain=Uri.parse(_domain).getAuthority();
}catch(Exception ignore){}
if(TextUtils.isEmpty(_domain))
return null;
}
String domain; String domain;
try{ try{
domain=IDN.toASCII(_domain); domain=IDN.toASCII(_domain);
}catch(IllegalArgumentException x){ }catch(IllegalArgumentException x){
return; return null;
} }
return domain;
}
private void loadInstanceInfo(String _domain){
String domain=normalizeInstanceDomain(_domain);
Instance cachedInstance=instancesCache.get(domain); Instance cachedInstance=instancesCache.get(domain);
if(cachedInstance!=null){ if(cachedInstance!=null){
for(CatalogInstance ci:filteredData){ for(CatalogInstance ci:filteredData){