Pickup instance when registering
This commit is contained in:
parent
e503a5ec95
commit
647c827ee4
|
@ -15,6 +15,7 @@ package app.fedilab.fedilabtube;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -60,6 +61,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public static PeertubeInformation peertubeInformation;
|
public static PeertubeInformation peertubeInformation;
|
||||||
|
|
||||||
|
public static int PICK_INSTANCE = 5641;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -302,9 +305,25 @@ public class MainActivity extends AppCompatActivity {
|
||||||
alt_bld.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
alt_bld.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||||
alt_bld.setNeutralButton(R.string.help, (dialog, which) -> {
|
alt_bld.setNeutralButton(R.string.help, (dialog, which) -> {
|
||||||
Intent intent = new Intent(MainActivity.this, InstancePickerActivity.class);
|
Intent intent = new Intent(MainActivity.this, InstancePickerActivity.class);
|
||||||
startActivity(intent);
|
startActivityForResult(intent, PICK_INSTANCE);
|
||||||
});
|
});
|
||||||
AlertDialog alert = alt_bld.create();
|
AlertDialog alert = alt_bld.create();
|
||||||
alert.show();
|
alert.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressLint("ApplySharedPref")
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (requestCode == PICK_INSTANCE && resultCode == Activity.RESULT_OK) {
|
||||||
|
if (data != null && data.getData() != null) {
|
||||||
|
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putString(Helper.PREF_INSTANCE, String.valueOf(data.getData()));
|
||||||
|
editor.commit();
|
||||||
|
recreate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -14,6 +14,11 @@ package app.fedilab.fedilabtube;
|
||||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
@ -24,6 +29,7 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
@ -39,15 +45,19 @@ import java.util.regex.Pattern;
|
||||||
import app.fedilab.fedilabtube.client.APIResponse;
|
import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||||
import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
||||||
|
import app.fedilab.fedilabtube.client.entities.Peertube;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
import app.fedilab.fedilabtube.helper.Helper;
|
||||||
import es.dmoral.toasty.Toasty;
|
import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
|
import static app.fedilab.fedilabtube.MainActivity.PICK_INSTANCE;
|
||||||
|
|
||||||
public class PeertubeRegisterActivity extends AppCompatActivity {
|
public class PeertubeRegisterActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
private Button signup;
|
private Button signup;
|
||||||
private TextView error_message;
|
private TextView error_message;
|
||||||
private String instance;
|
private String instance;
|
||||||
|
private TextInputEditText login_instance;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -61,16 +71,18 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
|
||||||
signup = findViewById(R.id.signup);
|
signup = findViewById(R.id.signup);
|
||||||
|
|
||||||
TextInputLayout login_instance_container = findViewById(R.id.login_instance_container);
|
TextInputLayout login_instance_container = findViewById(R.id.login_instance_container);
|
||||||
|
LinearLayout title_login_instance = findViewById(R.id.title_login_instance);
|
||||||
TextInputEditText username = findViewById(R.id.username);
|
TextInputEditText username = findViewById(R.id.username);
|
||||||
TextInputEditText email = findViewById(R.id.email);
|
TextInputEditText email = findViewById(R.id.email);
|
||||||
TextInputEditText password = findViewById(R.id.password);
|
TextInputEditText password = findViewById(R.id.password);
|
||||||
TextInputEditText password_confirm = findViewById(R.id.password_confirm);
|
TextInputEditText password_confirm = findViewById(R.id.password_confirm);
|
||||||
TextInputEditText login_instance = findViewById(R.id.login_instance);
|
login_instance = findViewById(R.id.login_instance);
|
||||||
CheckBox agreement = findViewById(R.id.agreement);
|
CheckBox agreement = findViewById(R.id.agreement);
|
||||||
error_message = findViewById(R.id.error_message);
|
error_message = findViewById(R.id.error_message);
|
||||||
|
|
||||||
if (BuildConfig.full_instances) {
|
if (BuildConfig.full_instances) {
|
||||||
login_instance_container.setVisibility(View.VISIBLE);
|
login_instance_container.setVisibility(View.VISIBLE);
|
||||||
|
title_login_instance.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
username.setOnFocusChangeListener((view, focused) -> {
|
username.setOnFocusChangeListener((view, focused) -> {
|
||||||
|
@ -83,6 +95,13 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Button instance_help = findViewById(R.id.instance_help);
|
||||||
|
|
||||||
|
instance_help.setOnClickListener(v -> {
|
||||||
|
Intent intent = new Intent(PeertubeRegisterActivity.this, InstancePickerActivity.class);
|
||||||
|
startActivityForResult(intent, PICK_INSTANCE);
|
||||||
|
});
|
||||||
|
|
||||||
email.setOnFocusChangeListener((view, focused) -> {
|
email.setOnFocusChangeListener((view, focused) -> {
|
||||||
if (!focused && email.getText() != null) {
|
if (!focused && email.getText() != null) {
|
||||||
Pattern patternUsername = Patterns.EMAIL_ADDRESS;
|
Pattern patternUsername = Patterns.EMAIL_ADDRESS;
|
||||||
|
@ -236,4 +255,17 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ApplySharedPref")
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (requestCode == PICK_INSTANCE && resultCode == Activity.RESULT_OK) {
|
||||||
|
if (data != null && data.getData() != null) {
|
||||||
|
String instance = String.valueOf(data.getData());
|
||||||
|
login_instance.setText(instance);
|
||||||
|
login_instance.setSelection(instance.length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -15,7 +15,10 @@ package app.fedilab.fedilabtube.drawer;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -36,6 +39,7 @@ import app.fedilab.fedilabtube.R;
|
||||||
import app.fedilab.fedilabtube.client.entities.Instance;
|
import app.fedilab.fedilabtube.client.entities.Instance;
|
||||||
import app.fedilab.fedilabtube.helper.RoundedBackgroundSpan;
|
import app.fedilab.fedilabtube.helper.RoundedBackgroundSpan;
|
||||||
|
|
||||||
|
import static android.app.Activity.RESULT_OK;
|
||||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,6 +126,14 @@ public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
holder.sensitive_content.setVisibility(View.GONE);
|
holder.sensitive_content.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
holder.followers_instance.setText(context.getString(R.string.followers_instance, String.valueOf(instance.getTotalInstanceFollowers())));
|
holder.followers_instance.setText(context.getString(R.string.followers_instance, String.valueOf(instance.getTotalInstanceFollowers())));
|
||||||
|
|
||||||
|
holder.pickup.setOnClickListener(v -> {
|
||||||
|
Intent data = new Intent();
|
||||||
|
String instanceHost = instance.getHost();
|
||||||
|
data.setData(Uri.parse(instanceHost));
|
||||||
|
((Activity) context).setResult(RESULT_OK, data);
|
||||||
|
((Activity) context).finish();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,12 +61,32 @@
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:layout_width="150dp"
|
android:id="@+id/title_login_instance"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_width="match_parent"
|
||||||
android:labelFor="@+id/login_instance"
|
android:orientation="horizontal"
|
||||||
android:text="@string/title_instance_login" />
|
android:layout_marginTop="20dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
|
||||||
|
android:labelFor="@+id/login_instance"
|
||||||
|
android:text="@string/title_instance_login" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/instance_help"
|
||||||
|
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:padding="2dp"
|
||||||
|
android:text="@string/help" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/login_instance_container"
|
android:id="@+id/login_instance_container"
|
||||||
|
|
Loading…
Reference in New Issue