Support proxy for Peertube

fix_reports
Thomas 2 years ago
parent be0a85cb3a
commit 42bdcaf6b6

@ -72,6 +72,7 @@ import androidx.core.app.ActivityOptionsCompat;
import androidx.core.view.GravityCompat;
import androidx.cursoradapter.widget.CursorAdapter;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -562,6 +563,52 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
}
}
public static void headerOptionInfoClick(Activity activity, NavHeaderMainBinding headerMainBinding, FragmentManager fragmentManager) {
PopupMenu popup = new PopupMenu(activity, headerMainBinding.headerOptionInfo);
popup.getMenuInflater()
.inflate(R.menu.main, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
int itemId = item.getItemId();
if (itemId == R.id.action_logout_account) {
AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(activity, Helper.dialogStyle());
alt_bld.setTitle(R.string.action_logout);
if (currentAccount.mastodon_account != null && currentAccount.instance != null) {
alt_bld.setMessage(activity.getString(R.string.logout_account_confirmation, currentAccount.mastodon_account.username, currentAccount.instance));
} else if (currentAccount.peertube_account != null && currentAccount.instance != null) {
alt_bld.setMessage(activity.getString(R.string.logout_account_confirmation, currentAccount.peertube_account.getUsername(), currentAccount.instance));
} else {
alt_bld.setMessage(activity.getString(R.string.logout_account_confirmation, "", ""));
}
alt_bld.setPositiveButton(R.string.action_logout, (dialog, id) -> {
dialog.dismiss();
try {
Helper.removeAccount(activity);
} catch (DBException e) {
e.printStackTrace();
}
});
alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alert = alt_bld.create();
alert.show();
return true;
} else if (itemId == R.id.action_proxy) {
(new ProxyActivity()).show(fragmentManager, null);
return true;
}
return true;
});
popup.show();
}
protected abstract void rateThisApp();
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
mamageNewIntent(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -891,43 +938,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
manageDrawerMenu(BaseMainActivity.this, binding.navView, headerMainBinding);
});
headerMainBinding.headerOptionInfo.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(BaseMainActivity.this, headerMainBinding.headerOptionInfo);
popup.getMenuInflater()
.inflate(R.menu.main, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
int itemId = item.getItemId();
if (itemId == R.id.action_logout_account) {
AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(BaseMainActivity.this, Helper.dialogStyle());
alt_bld.setTitle(R.string.action_logout);
if (currentAccount.mastodon_account != null && currentAccount.mastodon_account.username != null && currentAccount.instance != null) {
alt_bld.setMessage(getString(R.string.logout_account_confirmation, currentAccount.mastodon_account.username, currentAccount.instance));
} else if (currentAccount.mastodon_account != null && currentAccount.mastodon_account.acct != null) {
alt_bld.setMessage(getString(R.string.logout_account_confirmation, currentAccount.mastodon_account.acct, ""));
} else {
alt_bld.setMessage(getString(R.string.logout_account_confirmation, "", ""));
}
alt_bld.setPositiveButton(R.string.action_logout, (dialog, id) -> {
dialog.dismiss();
try {
Helper.removeAccount(BaseMainActivity.this);
} catch (DBException e) {
e.printStackTrace();
}
});
alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alert = alt_bld.create();
alert.show();
return true;
} else if (itemId == R.id.action_proxy) {
(new ProxyActivity()).show(getSupportFragmentManager(), null);
return true;
}
return true;
});
popup.show();
});
headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(BaseMainActivity.this, headerMainBinding, getSupportFragmentManager()));
//Toolbar search
binding.toolbarSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@ -1044,14 +1055,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
fetchRecentAccounts(BaseMainActivity.this, headerMainBinding);
}
protected abstract void rateThisApp();
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
mamageNewIntent(intent);
}
/**
* Open notifications tab when coming from a notification device
*

@ -19,6 +19,7 @@ import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.currentToken;
import static app.fedilab.android.BaseMainActivity.fetchRecentAccounts;
import static app.fedilab.android.BaseMainActivity.headerMenuOpen;
import static app.fedilab.android.BaseMainActivity.headerOptionInfoClick;
import static app.fedilab.android.BaseMainActivity.manageDrawerMenu;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE;
@ -306,7 +307,9 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
mainHandler.post(myRunnable);
}).start();
headerMainBinding.instanceInfo.setVisibility(View.GONE);
headerMainBinding.headerOptionInfo.setVisibility(View.GONE);
headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(PeertubeMainActivity.this, headerMainBinding, getSupportFragmentManager()));
binding.drawerNavView.addHeaderView(headerMainBinding.getRoot());
binding.drawerNavView.setNavigationItemSelectedListener(item -> {

@ -105,10 +105,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
@SuppressWarnings({"unused", "RedundantSuppression", "ConstantConditions"})
public class RetrofitPeertubeAPI {
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.build();
private final String finalUrl;
private final Context _context;
private final String instance;
@ -213,6 +210,11 @@ public class RetrofitPeertubeAPI {
}
private PeertubeService init() {
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.proxy(app.fedilab.android.mastodon.helper.Helper.getProxy(_context.getApplicationContext()))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(finalUrl)
.addConverterFactory(GsonConverterFactory.create())
@ -230,6 +232,11 @@ public class RetrofitPeertubeAPI {
if (!URLUtil.isValidUrl("https://" + instance)) {
return null;
}
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.proxy(app.fedilab.android.mastodon.helper.Helper.getProxy(_context.getApplicationContext()))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance)
.addConverterFactory(GsonConverterFactory.create())

Loading…
Cancel
Save