|
|
@ -16,15 +16,11 @@ package app.fedilab.android.peertube.activities;
|
|
|
|
|
|
|
|
|
|
|
|
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING;
|
|
|
|
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING;
|
|
|
|
import static app.fedilab.android.mastodon.helper.Helper.addFragment;
|
|
|
|
import static app.fedilab.android.mastodon.helper.Helper.addFragment;
|
|
|
|
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.INSTANCE_ADDRESS;
|
|
|
|
import static app.fedilab.android.peertube.helper.Helper.recreatePeertubeActivity;
|
|
|
|
import static app.fedilab.android.peertube.activities.PeertubeMainActivity.PICK_INSTANCE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.EditText;
|
|
|
@ -32,8 +28,6 @@ import android.widget.LinearLayout;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
@ -52,7 +46,6 @@ import app.fedilab.android.peertube.client.data.InstanceData;
|
|
|
|
import app.fedilab.android.peertube.client.entities.WellKnownNodeinfo;
|
|
|
|
import app.fedilab.android.peertube.client.entities.WellKnownNodeinfo;
|
|
|
|
import app.fedilab.android.peertube.drawer.AboutInstanceAdapter;
|
|
|
|
import app.fedilab.android.peertube.drawer.AboutInstanceAdapter;
|
|
|
|
import app.fedilab.android.peertube.fragment.FragmentLoginPickInstancePeertube;
|
|
|
|
import app.fedilab.android.peertube.fragment.FragmentLoginPickInstancePeertube;
|
|
|
|
import app.fedilab.android.peertube.helper.Helper;
|
|
|
|
|
|
|
|
import app.fedilab.android.peertube.helper.HelperInstance;
|
|
|
|
import app.fedilab.android.peertube.helper.HelperInstance;
|
|
|
|
import app.fedilab.android.peertube.sqlite.StoredInstanceDAO;
|
|
|
|
import app.fedilab.android.peertube.sqlite.StoredInstanceDAO;
|
|
|
|
import app.fedilab.android.peertube.viewmodel.InfoInstanceVM;
|
|
|
|
import app.fedilab.android.peertube.viewmodel.InfoInstanceVM;
|
|
|
@ -67,13 +60,26 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
|
|
|
|
private AboutInstanceAdapter aboutInstanceAdapter;
|
|
|
|
private AboutInstanceAdapter aboutInstanceAdapter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ApplySharedPref")
|
|
|
|
|
|
|
|
public static void showRadioButtonDialogFullInstances(Activity activity, FragmentManager fragmentManager) {
|
|
|
|
@Override
|
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(activity);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
binding = ActivityManageInstancesPeertubeBinding.inflate(getLayoutInflater());
|
|
|
|
|
|
|
|
View view = binding.getRoot();
|
|
|
|
|
|
|
|
setContentView(view);
|
|
|
|
|
|
|
|
if (getSupportActionBar() != null) {
|
|
|
|
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.loader.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
binding.noAction.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
binding.lvInstances.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
binding.actionButton.setOnClickListener(v -> {
|
|
|
|
|
|
|
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
|
|
|
AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(this);
|
|
|
|
alt_bld.setTitle(R.string.instance_choice);
|
|
|
|
alt_bld.setTitle(R.string.instance_choice);
|
|
|
|
String instance = HelperInstance.getLiveInstance(activity);
|
|
|
|
String instance = HelperInstance.getLiveInstance(this);
|
|
|
|
final EditText input = new EditText(activity);
|
|
|
|
final EditText input = new EditText(this);
|
|
|
|
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
|
|
|
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT);
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT);
|
|
|
@ -90,21 +96,21 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
|
|
|
|
URL url = new URL(newInstance);
|
|
|
|
URL url = new URL(newInstance);
|
|
|
|
newInstance = url.getHost();
|
|
|
|
newInstance = url.getHost();
|
|
|
|
|
|
|
|
|
|
|
|
WellKnownNodeinfo.NodeInfo instanceNodeInfo = new RetrofitPeertubeAPI(activity, newInstance, null).getNodeInfo();
|
|
|
|
WellKnownNodeinfo.NodeInfo instanceNodeInfo = new RetrofitPeertubeAPI(this, newInstance, null).getNodeInfo();
|
|
|
|
if (instanceNodeInfo.getSoftware() != null && instanceNodeInfo.getSoftware().getName().trim().toLowerCase().compareTo("peertube") == 0) {
|
|
|
|
if (instanceNodeInfo.getSoftware() != null && instanceNodeInfo.getSoftware().getName().trim().toLowerCase().compareTo("peertube") == 0) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, newInstance);
|
|
|
|
editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, newInstance);
|
|
|
|
editor.commit();
|
|
|
|
editor.commit();
|
|
|
|
newInstance = newInstance.trim().toLowerCase();
|
|
|
|
newInstance = newInstance.trim().toLowerCase();
|
|
|
|
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance();
|
|
|
|
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(this, newInstance, null).getAboutInstance();
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(this.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
new StoredInstanceDAO(activity, db).insertInstance(aboutInstance, newInstance);
|
|
|
|
new StoredInstanceDAO(this, db).insertInstance(aboutInstance, newInstance);
|
|
|
|
activity.runOnUiThread(() -> {
|
|
|
|
this.runOnUiThread(() -> {
|
|
|
|
dialog.dismiss();
|
|
|
|
dialog.dismiss();
|
|
|
|
Helper.logoutNoRemoval(activity);
|
|
|
|
recreatePeertubeActivity(this);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
activity.runOnUiThread(() -> Toasty.error(activity, activity.getString(R.string.not_valide_instance), Toast.LENGTH_LONG).show());
|
|
|
|
runOnUiThread(() -> Toasty.error(this, getString(R.string.not_valide_instance), Toast.LENGTH_LONG).show());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -113,38 +119,13 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns
|
|
|
|
}).start());
|
|
|
|
}).start());
|
|
|
|
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) -> {
|
|
|
|
fragmentManager.setFragmentResultListener(PICK_INSTANCE, (LifecycleOwner) activity, (requestKey, result) -> {
|
|
|
|
|
|
|
|
new Thread(() -> {
|
|
|
|
|
|
|
|
String newInstance = result.getString(INSTANCE_ADDRESS);
|
|
|
|
|
|
|
|
InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance();
|
|
|
|
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
|
|
|
|
new StoredInstanceDAO(activity, db).insertInstance(aboutInstance, newInstance);
|
|
|
|
|
|
|
|
activity.runOnUiThread(() -> new Handler().post(() -> Helper.logoutNoRemoval(activity)));
|
|
|
|
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
fragmentManager.clearFragmentResultListener(PICK_INSTANCE);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
addFragment(
|
|
|
|
addFragment(
|
|
|
|
fragmentManager, android.R.id.content, new FragmentLoginPickInstancePeertube(),
|
|
|
|
getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(),
|
|
|
|
null, null, FragmentLoginPickInstancePeertube.class.getName());
|
|
|
|
null, null, FragmentLoginPickInstancePeertube.class.getName());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
AlertDialog alert = alt_bld.create();
|
|
|
|
AlertDialog alert = alt_bld.create();
|
|
|
|
alert.show();
|
|
|
|
alert.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
binding = ActivityManageInstancesPeertubeBinding.inflate(getLayoutInflater());
|
|
|
|
|
|
|
|
View view = binding.getRoot();
|
|
|
|
|
|
|
|
setContentView(view);
|
|
|
|
|
|
|
|
if (getSupportActionBar() != null) {
|
|
|
|
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.loader.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
binding.noAction.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
binding.lvInstances.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
binding.actionButton.setOnClickListener(v -> showRadioButtonDialogFullInstances(ManageInstancesActivity.this, getSupportFragmentManager()));
|
|
|
|
|
|
|
|
aboutInstances = new ArrayList<>();
|
|
|
|
aboutInstances = new ArrayList<>();
|
|
|
|
aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances);
|
|
|
|
aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances);
|
|
|
|
aboutInstanceAdapter.allInstancesRemoved = this;
|
|
|
|
aboutInstanceAdapter.allInstancesRemoved = this;
|
|
|
|