diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index c98380d..4a69fa8 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -15,6 +15,7 @@ package app.fedilab.fedilabtube; * see . */ 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(); + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java index f84f5ce..1a05923 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java @@ -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 . */ +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()); + } + } + } + } \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/InstanceAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/InstanceAdapter.java index 5250ce3..7ee070b 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/InstanceAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/InstanceAdapter.java @@ -15,7 +15,10 @@ package app.fedilab.fedilabtube.drawer; * see . */ +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 { + Intent data = new Intent(); + String instanceHost = instance.getHost(); + data.setData(Uri.parse(instanceHost)); + ((Activity) context).setResult(RESULT_OK, data); + ((Activity) context).finish(); + }); } @Override diff --git a/app/src/main/res/layout/activity_register_peertube.xml b/app/src/main/res/layout/activity_register_peertube.xml index 8eea78b..fe6fdc4 100644 --- a/app/src/main/res/layout/activity_register_peertube.xml +++ b/app/src/main/res/layout/activity_register_peertube.xml @@ -61,12 +61,32 @@ android:visibility="gone" /> - + android:layout_width="match_parent" + android:orientation="horizontal" + android:layout_marginTop="20dp"> + + + +