comment #346 - Some improvements
This commit is contained in:
parent
a7fa7b91ec
commit
2cfd868d6a
|
@ -96,7 +96,6 @@ public class LoginActivity extends BaseActivity {
|
|||
private static boolean client_id_for_webview = false;
|
||||
private static String instance;
|
||||
private final int PICK_IMPORT = 5557;
|
||||
boolean isLoadingInstance = false;
|
||||
private AutoCompleteTextView login_instance;
|
||||
private EditText login_uid;
|
||||
private EditText login_passwd;
|
||||
|
@ -104,13 +103,12 @@ public class LoginActivity extends BaseActivity {
|
|||
private Button connectionButton, connect_button;
|
||||
private String actionToken;
|
||||
private String autofilledInstance;
|
||||
private String social;
|
||||
private UpdateAccountInfoAsyncTask.SOCIAL socialNetwork;
|
||||
private String basicAuth;
|
||||
private InstanceNodeInfo instanceNodeInfo;
|
||||
private ConstraintLayout step_login_credential, step_instance;
|
||||
private TextView instance_chosen;
|
||||
private ImageView info_instance;
|
||||
private Thread thread = null;
|
||||
|
||||
public static String redirectUserToAuthorizeAndLogin(Context context, UpdateAccountInfoAsyncTask.SOCIAL socialNetwork, String clientId, String instance) {
|
||||
String queryString = Helper.CLIENT_ID + "=" + clientId;
|
||||
|
@ -132,7 +130,6 @@ public class LoginActivity extends BaseActivity {
|
|||
admin = false;
|
||||
if (b != null) {
|
||||
autofilledInstance = b.getString("instance", null);
|
||||
social = b.getString("social", null);
|
||||
if (instanceNodeInfo != null) {
|
||||
socialNetwork = Helper.setSoftware(instanceNodeInfo.getName(), false);
|
||||
}
|
||||
|
@ -247,7 +244,7 @@ public class LoginActivity extends BaseActivity {
|
|||
instance_chosen = findViewById(R.id.instance_chosen);
|
||||
step_instance = findViewById(R.id.step_instance);
|
||||
connectionButton = findViewById(R.id.login_button);
|
||||
info_instance = findViewById(R.id.info_instance);
|
||||
ImageView info_instance = findViewById(R.id.info_instance);
|
||||
ImageView main_logo = findViewById(R.id.main_logo);
|
||||
main_logo.setImageResource(Helper.getMainLogo(getApplicationContext()));
|
||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
|
||||
|
@ -332,22 +329,34 @@ public class LoginActivity extends BaseActivity {
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (s.length() > 2 && !isLoadingInstance) {
|
||||
|
||||
if (s.length() > 2) {
|
||||
|
||||
final String action = "/instances/search";
|
||||
final HashMap<String, String> parameters = new HashMap<>();
|
||||
parameters.put("q", s.toString().trim());
|
||||
String query = s.toString().trim();
|
||||
if (query.startsWith("http://")){
|
||||
query =query.replace("http://", "");
|
||||
}
|
||||
if (query.startsWith("https://")){
|
||||
query =query.replace("https://", "");
|
||||
}
|
||||
parameters.put("q", query);
|
||||
parameters.put("count", String.valueOf(1000));
|
||||
parameters.put("name", String.valueOf(true));
|
||||
isLoadingInstance = true;
|
||||
if (oldSearch == null || !oldSearch.equals(s.toString().trim()))
|
||||
new Thread(new Runnable() {
|
||||
if( thread != null && thread.isAlive()){
|
||||
thread.interrupt();
|
||||
thread = null;
|
||||
}
|
||||
|
||||
if (oldSearch == null || !oldSearch.equals(s.toString().trim())) {
|
||||
thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final String response = new HttpsConnection(LoginActivity.this, instance).get("https://instances.social/api/1.0" + action, 30, parameters, Helper.THEKINRAR_SECRET_TOKEN);
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
isLoadingInstance = false;
|
||||
String[] instances;
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
|
@ -374,16 +383,17 @@ public class LoginActivity extends BaseActivity {
|
|||
oldSearch = s.toString().trim();
|
||||
|
||||
} catch (JSONException ignored) {
|
||||
isLoadingInstance = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
isLoadingInstance = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -468,6 +478,12 @@ public class LoginActivity extends BaseActivity {
|
|||
private void retrievesClientId() {
|
||||
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
String instanceFromField = login_instance.getText().toString().trim();
|
||||
if (instanceFromField.startsWith("http://")){
|
||||
instanceFromField =instanceFromField.replace("http://", "");
|
||||
}
|
||||
if (instanceFromField.startsWith("https://")){
|
||||
instanceFromField =instanceFromField.replace("https://", "");
|
||||
}
|
||||
String host = instanceFromField;
|
||||
try {
|
||||
URL url = new URL(instanceFromField);
|
||||
|
|
|
@ -1832,6 +1832,12 @@ public class API {
|
|||
|
||||
String response;
|
||||
InstanceNodeInfo instanceNodeInfo = new InstanceNodeInfo();
|
||||
if( domain.startsWith("http://")){
|
||||
domain = domain.replace("http://","");
|
||||
}
|
||||
if( domain.startsWith("https://")){
|
||||
domain = domain.replace("https://","");
|
||||
}
|
||||
try {
|
||||
response = new HttpsConnection(context, domain).get("https://" + domain + "/.well-known/nodeinfo", 30, null, null);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("links");
|
||||
|
|
|
@ -649,9 +649,7 @@
|
|||
</string-array>
|
||||
|
||||
|
||||
<string name="showcase_instance">
|
||||
In this field, you need to write your instance host name.\nFor example, if you created your account on https://mastodon.social\nJust write <b>mastodon.social</b>\n
|
||||
You can start writing first letters and names will be suggested.
|
||||
<string name="showcase_instance">In this field, you need to write your instance domain.\nFor example, if you created your account on https://mastodon.social\nJust write <b>mastodon.social</b>\nYou can start writing first letters and names will be suggested.
|
||||
</string>
|
||||
<string name="more_information">More information</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue