Add more elements

This commit is contained in:
tom79 2019-11-05 17:55:12 +01:00
parent b21c94e763
commit c6657ebfe0
8 changed files with 42 additions and 12 deletions

View File

@ -209,7 +209,7 @@ public class MastodonRegisterActivity extends BaseActivity implements OnRetrieve
accountCreation.setPassword(password.getText().toString().trim());
accountCreation.setPasswordConfirm(password_confirm.getText().toString().trim());
accountCreation.setUsername(username.getText().toString().trim());
new CreateMastodonAccountAsyncTask(MastodonRegisterActivity.this, accountCreation, instance, MastodonRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
new CreateMastodonAccountAsyncTask(MastodonRegisterActivity.this,RetrieveInstanceRegAsyncTask.instanceType.MASTODON, accountCreation, instance, MastodonRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
});

View File

@ -51,6 +51,7 @@ import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.asynctasks.CreateMastodonAccountAsyncTask;
import app.fedilab.android.asynctasks.RetrieveInstanceRegAsyncTask;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.AccountCreation;
import app.fedilab.android.client.Entities.InstanceReg;
@ -177,7 +178,7 @@ public class MastodonShareRegisterActivity extends BaseActivity implements OnRet
accountCreation.setPassword(password.getText().toString().trim());
accountCreation.setPasswordConfirm(password_confirm.getText().toString().trim());
accountCreation.setUsername(username.getText().toString().trim());
new CreateMastodonAccountAsyncTask(MastodonShareRegisterActivity.this, accountCreation, instance, MastodonShareRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
new CreateMastodonAccountAsyncTask(MastodonShareRegisterActivity.this, RetrieveInstanceRegAsyncTask.instanceType.MASTODON, accountCreation, instance, MastodonShareRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
});

View File

@ -162,7 +162,7 @@ public class PeertubeRegisterActivity extends BaseActivity implements OnRetrieve
accountCreation.setPassword(password.getText().toString().trim());
accountCreation.setPasswordConfirm(password_confirm.getText().toString().trim());
accountCreation.setUsername(username.getText().toString().trim());
new CreateMastodonAccountAsyncTask(PeertubeRegisterActivity.this, accountCreation, instance, PeertubeRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
new CreateMastodonAccountAsyncTask(PeertubeRegisterActivity.this, RetrieveInstanceRegAsyncTask.instanceType.PEERTUBE, accountCreation, instance, PeertubeRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
});
@ -191,7 +191,7 @@ public class PeertubeRegisterActivity extends BaseActivity implements OnRetrieve
}
public void pickupInstance(String instance) {
LinearLayout form_container = findViewById(R.id.form_container);
LinearLayout drawer_layout = findViewById(R.id.drawer_layout);
@ -246,10 +246,8 @@ public class PeertubeRegisterActivity extends BaseActivity implements OnRetrieve
username_indicator.setText(getString(R.string.username_indicator, instance));
String tos = getString(R.string.tos);
String serverrules = getString(R.string.server_rules);
String content_agreement = getString(R.string.agreement_check,
"<a href='https://" + instance + "/about/more' >" + serverrules + "</a>",
"<a href='https://" + instance + "/terms' >" + tos + "</a>"
String content_agreement = getString(R.string.agreement_check_peertube,
"<a href='https://" + instance + "/about/instance#terms-section' >" + tos + "</a>"
);
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
agreement_text.setText(Html.fromHtml(content_agreement));

View File

@ -22,6 +22,7 @@ import java.lang.ref.WeakReference;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.AccountCreation;
import app.fedilab.android.client.PeertubeAPI;
import app.fedilab.android.interfaces.OnPostStatusActionInterface;
@ -38,17 +39,23 @@ public class CreateMastodonAccountAsyncTask extends AsyncTask<Void, Void, Void>
private AccountCreation accountCreation;
private WeakReference<Context> contextReference;
private String instance;
private RetrieveInstanceRegAsyncTask.instanceType type;
public CreateMastodonAccountAsyncTask(Context context, AccountCreation accountCreation, String instance, OnPostStatusActionInterface onPostStatusActionInterface) {
public CreateMastodonAccountAsyncTask(Context context, RetrieveInstanceRegAsyncTask.instanceType type, AccountCreation accountCreation, String instance, OnPostStatusActionInterface onPostStatusActionInterface) {
this.contextReference = new WeakReference<>(context);
this.listener = onPostStatusActionInterface;
this.accountCreation = accountCreation;
this.instance = instance;
this.type = type;
}
@Override
protected Void doInBackground(Void... params) {
apiResponse = new API(contextReference.get(), instance, null).createAccount(accountCreation);
if( type == RetrieveInstanceRegAsyncTask.instanceType.MASTODON) {
apiResponse = new API(contextReference.get(), instance, null).createAccount(accountCreation);
}else{
apiResponse = new PeertubeAPI(contextReference.get(), instance, null).createAccount(accountCreation);
}
return null;
}

View File

@ -900,7 +900,7 @@ public class API {
params.put("password", accountCreation.getPassword());
params.put("agreement", "true");
params.put("locale", Locale.getDefault().getLanguage());
response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/accounts"), 10, params, app_token);
response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/accounts"), 30, params, app_token);
/*res = new JSONObject(response);
String access_token = res.getString("access_token");

View File

@ -39,6 +39,7 @@ import java.util.Map;
import app.fedilab.android.R;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.AccountCreation;
import app.fedilab.android.client.Entities.Attachment;
import app.fedilab.android.client.Entities.Conversation;
import app.fedilab.android.client.Entities.Emojis;
@ -403,6 +404,26 @@ public class PeertubeAPI {
}
public APIResponse createAccount(AccountCreation accountCreation) {
apiResponse = new APIResponse();
try {
HashMap<String, String> params = new HashMap<>();
params.put("username", accountCreation.getUsername());
params.put("email", accountCreation.getEmail());
params.put("password", accountCreation.getPassword());
String response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/users/register"), 30, params, null);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}
return apiResponse;
}
/***
* Verifiy credential of the authenticated user *synchronously*
* @return Account

View File

@ -174,8 +174,10 @@
<TextView
android:id="@+id/agreement_text"
android:text="@string/agreement_check_peertube"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"/>
</LinearLayout>
<Button

View File

@ -1246,4 +1246,5 @@
<string name="order_by">Order by</string>
<string name="title_video_peertube">Title for the video</string>
<string name="join_peertube">Join Peertube</string>
<string name="agreement_check_peertube">I am at least 16 years old and agree to the %1$s of this instance</string>
</resources>