improve Peertube instance picker behaviour

This commit is contained in:
Thomas 2023-03-16 17:36:55 +01:00
parent 740ce71ac9
commit 979739cc21
4 changed files with 36 additions and 12 deletions

View file

@ -53,14 +53,13 @@ import app.fedilab.android.sqlite.Sqlite;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
public class ManageInstancesActivity extends BaseBarActivity implements AboutInstanceAdapter.AllInstancesRemoved { public class ManageInstancesActivity extends BaseBarActivity implements AboutInstanceAdapter.InstanceActions {
private ActivityManageInstancesPeertubeBinding binding; private ActivityManageInstancesPeertubeBinding binding;
private List<InstanceData.AboutInstance> aboutInstances; private List<InstanceData.AboutInstance> aboutInstances;
private AboutInstanceAdapter aboutInstanceAdapter; private AboutInstanceAdapter aboutInstanceAdapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -108,6 +107,7 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
this.runOnUiThread(() -> { this.runOnUiThread(() -> {
dialog.dismiss(); dialog.dismiss();
recreatePeertubeActivity(this); recreatePeertubeActivity(this);
finish();
}); });
} else { } else {
runOnUiThread(() -> Toasty.error(this, getString(R.string.not_valide_instance), Toast.LENGTH_LONG).show()); runOnUiThread(() -> Toasty.error(this, getString(R.string.not_valide_instance), Toast.LENGTH_LONG).show());
@ -128,7 +128,7 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
}); });
aboutInstances = new ArrayList<>(); aboutInstances = new ArrayList<>();
aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances); aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances);
aboutInstanceAdapter.allInstancesRemoved = this; aboutInstanceAdapter.instanceActions = this;
binding.lvInstances.setAdapter(aboutInstanceAdapter); binding.lvInstances.setAdapter(aboutInstanceAdapter);
LinearLayoutManager layoutManager LinearLayoutManager layoutManager
= new LinearLayoutManager(ManageInstancesActivity.this); = new LinearLayoutManager(ManageInstancesActivity.this);
@ -172,4 +172,10 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
binding.noAction.setVisibility(View.VISIBLE); binding.noAction.setVisibility(View.VISIBLE);
binding.lvInstances.setVisibility(View.GONE); binding.lvInstances.setVisibility(View.GONE);
} }
@Override
public void onFinished() {
recreatePeertubeActivity(this);
finish();
}
} }

View file

@ -121,6 +121,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
private DisplayOverviewFragment overviewFragment; private DisplayOverviewFragment overviewFragment;
private ActivityMainPeertubeBinding binding; private ActivityMainPeertubeBinding binding;
private boolean keepRemote = false;
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() { private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
@Override @Override
@ -128,6 +129,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
Bundle b = intent.getExtras(); Bundle b = intent.getExtras();
if (b != null) { if (b != null) {
if (b.getBoolean(app.fedilab.android.mastodon.helper.Helper.RECEIVE_RECREATE_PEERTUBE_ACTIVITY, false)) { if (b.getBoolean(app.fedilab.android.mastodon.helper.Helper.RECEIVE_RECREATE_PEERTUBE_ACTIVITY, false)) {
keepRemote = true;
recreate(); recreate();
} }
} }
@ -147,7 +149,9 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
binding = null; binding = null;
typeOfConnection = TypeOfConnection.NORMAL; if (!keepRemote) {
typeOfConnection = TypeOfConnection.NORMAL;
}
LocalBroadcastManager.getInstance(PeertubeMainActivity.this).unregisterReceiver(broadcast_data); LocalBroadcastManager.getInstance(PeertubeMainActivity.this).unregisterReceiver(broadcast_data);
} }

View file

@ -16,7 +16,7 @@ package app.fedilab.android.peertube.drawer;
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY; import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
@ -53,7 +53,7 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
private final List<InstanceData.AboutInstance> aboutInstances; private final List<InstanceData.AboutInstance> aboutInstances;
public AllInstancesRemoved allInstancesRemoved; public InstanceActions instanceActions;
private Context context; private Context context;
public AboutInstanceAdapter(List<InstanceData.AboutInstance> aboutInstances) { public AboutInstanceAdapter(List<InstanceData.AboutInstance> aboutInstances) {
@ -126,12 +126,12 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
} }
holder.binding.aboutInstanceName.setText(aboutInstance.getName()); holder.binding.aboutInstanceName.setText(aboutInstance.getName());
holder.binding.instanceContainer.setOnClickListener(v -> { holder.binding.pickup.setOnClickListener(v -> {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(PREF_USER_INSTANCE, aboutInstance.getHost()); editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, aboutInstance.getHost());
editor.commit(); editor.commit();
//Helper.logoutNoRemoval((Activity) context); instanceActions.onFinished();
}); });
holder.binding.instanceMore.setOnClickListener(v -> { holder.binding.instanceMore.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(context, holder.binding.instanceMore); PopupMenu popup = new PopupMenu(context, holder.binding.instanceMore);
@ -153,7 +153,7 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
notifyItemRemoved(i); notifyItemRemoved(i);
if (aboutInstances.size() == 0) { if (aboutInstances.size() == 0) {
allInstancesRemoved.onAllInstancesRemoved(); instanceActions.onAllInstancesRemoved();
} }
}; };
mainHandler.post(myRunnable); mainHandler.post(myRunnable);
@ -170,8 +170,10 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter<RecyclerView.View
}); });
} }
public interface AllInstancesRemoved { public interface InstanceActions {
void onAllInstancesRemoved(); void onAllInstancesRemoved();
void onFinished();
} }
static class ViewHolder extends RecyclerView.ViewHolder { static class ViewHolder extends RecyclerView.ViewHolder {

View file

@ -18,16 +18,18 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/instance_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal" android:divider="?android:dividerHorizontal"
android:orientation="vertical" android:orientation="vertical"
android:clickable="true"
android:focusable="true"
android:showDividers="end"> android:showDividers="end">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/instance_container"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"> android:layout_marginBottom="5dp">
@ -74,5 +76,15 @@
android:src="@drawable/ic_baseline_more_vert_24" android:src="@drawable/ic_baseline_more_vert_24"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/pickup"
style="@style/Widget.Material3.Button.ElevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/pickup_instance"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/about_instance_description" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout> </LinearLayout>