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