Pickup instance when registering

This commit is contained in:
Thomas 2020-09-17 19:01:31 +02:00
parent e503a5ec95
commit 647c827ee4
4 changed files with 90 additions and 7 deletions

View File

@ -15,6 +15,7 @@ package app.fedilab.fedilabtube;
* 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;
@ -60,6 +61,8 @@ public class MainActivity extends AppCompatActivity {
public static PeertubeInformation peertubeInformation;
public static int PICK_INSTANCE = 5641;
@Override
protected void onCreate(Bundle 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.setNeutralButton(R.string.help, (dialog, which) -> {
Intent intent = new Intent(MainActivity.this, InstancePickerActivity.class);
startActivity(intent);
startActivityForResult(intent, PICK_INSTANCE);
});
AlertDialog alert = alt_bld.create();
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();
}
}
}
}

View File

@ -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,
* 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.Handler;
import android.os.Looper;
@ -24,6 +29,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
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.PeertubeAPI;
import app.fedilab.fedilabtube.client.entities.AccountCreation;
import app.fedilab.fedilabtube.client.entities.Peertube;
import app.fedilab.fedilabtube.helper.Helper;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.MainActivity.PICK_INSTANCE;
public class PeertubeRegisterActivity extends AppCompatActivity {
private Button signup;
private TextView error_message;
private String instance;
private TextInputEditText login_instance;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -61,16 +71,18 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
signup = findViewById(R.id.signup);
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 email = findViewById(R.id.email);
TextInputEditText password = findViewById(R.id.password);
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);
error_message = findViewById(R.id.error_message);
if (BuildConfig.full_instances) {
login_instance_container.setVisibility(View.VISIBLE);
title_login_instance.setVisibility(View.VISIBLE);
}
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) -> {
if (!focused && email.getText() != null) {
Pattern patternUsername = Patterns.EMAIL_ADDRESS;
@ -236,4 +255,17 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
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());
}
}
}
}

View File

@ -15,7 +15,10 @@ package app.fedilab.fedilabtube.drawer;
* see <http://www.gnu.org/licenses>. */
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.view.LayoutInflater;
@ -36,6 +39,7 @@ import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.entities.Instance;
import app.fedilab.fedilabtube.helper.RoundedBackgroundSpan;
import static android.app.Activity.RESULT_OK;
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.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

View File

@ -61,12 +61,32 @@
android:visibility="gone" />
<TextView
android:layout_width="150dp"
<LinearLayout
android:id="@+id/title_login_instance"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:labelFor="@+id/login_instance"
android:text="@string/title_instance_login" />
android:layout_width="match_parent"
android:orientation="horizontal"
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
android:id="@+id/login_instance_container"