mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Support proxy for Peertube
This commit is contained in:
		
							parent
							
								
									be0a85cb3a
								
							
						
					
					
						commit
						42bdcaf6b6
					
				
					 3 changed files with 63 additions and 50 deletions
				
			
		|  | @ -72,6 +72,7 @@ import androidx.core.app.ActivityOptionsCompat; | ||||||
| import androidx.core.view.GravityCompat; | import androidx.core.view.GravityCompat; | ||||||
| import androidx.cursoradapter.widget.CursorAdapter; | import androidx.cursoradapter.widget.CursorAdapter; | ||||||
| import androidx.fragment.app.Fragment; | import androidx.fragment.app.Fragment; | ||||||
|  | import androidx.fragment.app.FragmentManager; | ||||||
| import androidx.fragment.app.FragmentTransaction; | import androidx.fragment.app.FragmentTransaction; | ||||||
| import androidx.lifecycle.ViewModelProvider; | import androidx.lifecycle.ViewModelProvider; | ||||||
| import androidx.localbroadcastmanager.content.LocalBroadcastManager; | 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 |     @Override | ||||||
|     protected void onCreate(Bundle savedInstanceState) { |     protected void onCreate(Bundle savedInstanceState) { | ||||||
|         super.onCreate(savedInstanceState); |         super.onCreate(savedInstanceState); | ||||||
|  | @ -891,43 +938,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|             manageDrawerMenu(BaseMainActivity.this, binding.navView, headerMainBinding); |             manageDrawerMenu(BaseMainActivity.this, binding.navView, headerMainBinding); | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         headerMainBinding.headerOptionInfo.setOnClickListener(v -> { |         headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(BaseMainActivity.this, headerMainBinding, getSupportFragmentManager())); | ||||||
|             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(); |  | ||||||
|         }); |  | ||||||
| 
 | 
 | ||||||
|         //Toolbar search |         //Toolbar search | ||||||
|         binding.toolbarSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() { |         binding.toolbarSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | ||||||
|  | @ -1044,14 +1055,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|         fetchRecentAccounts(BaseMainActivity.this, headerMainBinding); |         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 |      * 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.currentToken; | ||||||
| import static app.fedilab.android.BaseMainActivity.fetchRecentAccounts; | import static app.fedilab.android.BaseMainActivity.fetchRecentAccounts; | ||||||
| import static app.fedilab.android.BaseMainActivity.headerMenuOpen; | 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.BaseMainActivity.manageDrawerMenu; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; | ||||||
|  | @ -306,7 +307,9 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
|             mainHandler.post(myRunnable); |             mainHandler.post(myRunnable); | ||||||
|         }).start(); |         }).start(); | ||||||
|         headerMainBinding.instanceInfo.setVisibility(View.GONE); |         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.addHeaderView(headerMainBinding.getRoot()); | ||||||
| 
 | 
 | ||||||
|         binding.drawerNavView.setNavigationItemSelectedListener(item -> { |         binding.drawerNavView.setNavigationItemSelectedListener(item -> { | ||||||
|  |  | ||||||
|  | @ -105,10 +105,7 @@ import retrofit2.converter.gson.GsonConverterFactory; | ||||||
| @SuppressWarnings({"unused", "RedundantSuppression", "ConstantConditions"}) | @SuppressWarnings({"unused", "RedundantSuppression", "ConstantConditions"}) | ||||||
| public class RetrofitPeertubeAPI { | public class RetrofitPeertubeAPI { | ||||||
| 
 | 
 | ||||||
|     final OkHttpClient okHttpClient = new OkHttpClient.Builder() | 
 | ||||||
|             .readTimeout(60, TimeUnit.SECONDS) |  | ||||||
|             .connectTimeout(60, TimeUnit.SECONDS) |  | ||||||
|             .build(); |  | ||||||
|     private final String finalUrl; |     private final String finalUrl; | ||||||
|     private final Context _context; |     private final Context _context; | ||||||
|     private final String instance; |     private final String instance; | ||||||
|  | @ -213,6 +210,11 @@ public class RetrofitPeertubeAPI { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private PeertubeService init() { |     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() |         Retrofit retrofit = new Retrofit.Builder() | ||||||
|                 .baseUrl(finalUrl) |                 .baseUrl(finalUrl) | ||||||
|                 .addConverterFactory(GsonConverterFactory.create()) |                 .addConverterFactory(GsonConverterFactory.create()) | ||||||
|  | @ -230,6 +232,11 @@ public class RetrofitPeertubeAPI { | ||||||
|         if (!URLUtil.isValidUrl("https://" + instance)) { |         if (!URLUtil.isValidUrl("https://" + instance)) { | ||||||
|             return null; |             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() |         Retrofit retrofit = new Retrofit.Builder() | ||||||
|                 .baseUrl("https://" + instance) |                 .baseUrl("https://" + instance) | ||||||
|                 .addConverterFactory(GsonConverterFactory.create()) |                 .addConverterFactory(GsonConverterFactory.create()) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue