mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Move admin request in menu
This commit is contained in:
		
							parent
							
								
									1f347ccf98
								
							
						
					
					
						commit
						35c248bcb2
					
				
					 4 changed files with 31 additions and 12 deletions
				
			
		|  | @ -149,6 +149,10 @@ public class LoginActivity extends BaseActivity { | |||
|             editor.putBoolean(getString(R.string.SET_EMBEDDED_BROWSER), !item.isChecked()); | ||||
|             editor.apply(); | ||||
|             return false; | ||||
|         } else if (id == R.id.action_request_admin) { | ||||
|             item.setChecked(!item.isChecked()); | ||||
|             requestedAdmin = item.isChecked(); | ||||
|             return false; | ||||
|         } | ||||
|         return super.onOptionsItemSelected(item); | ||||
|     } | ||||
|  |  | |||
|  | @ -76,7 +76,6 @@ public class FragmentLoginMain extends Fragment { | |||
| 
 | ||||
|         binding.menuIcon.setOnClickListener(this::showMenu); | ||||
|         binding.loginInstance.setOnItemClickListener((parent, view, position, id) -> oldSearch = parent.getItemAtPosition(position).toString().trim()); | ||||
|         binding.adminScope.setOnCheckedChangeListener((compoundButton, checked) -> ((LoginActivity) requireActivity()).setAdmin(checked)); | ||||
|         binding.loginInstance.addTextChangedListener(new TextWatcher() { | ||||
|             @Override | ||||
|             public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||||
|  | @ -173,9 +172,11 @@ public class FragmentLoginMain extends Fragment { | |||
|         MenuInflater menuInflater = popupMenu.getMenuInflater(); | ||||
|         menuInflater.inflate(R.menu.main_login, popupMenu.getMenu()); | ||||
|         MenuItem customTabItem = popupMenu.getMenu().findItem(R.id.action_custom_tabs); | ||||
|         MenuItem adminTabItem = popupMenu.getMenu().findItem(R.id.action_request_admin); | ||||
|         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); | ||||
|         boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true); | ||||
|         customTabItem.setChecked(!embedded_browser); | ||||
|         adminTabItem.setChecked(((LoginActivity) requireActivity()).requestedAdmin()); | ||||
|         popupMenu.setOnMenuItemClickListener(item -> { | ||||
|             int itemId = item.getItemId(); | ||||
|             if (itemId == R.id.action_proxy) { | ||||
|  | @ -200,6 +201,23 @@ public class FragmentLoginMain extends Fragment { | |||
|                     } | ||||
|                 }); | ||||
|                 editor.apply(); | ||||
|             } else if (itemId == R.id.action_request_admin) { | ||||
|                 boolean checked = !((LoginActivity) requireActivity()).requestedAdmin(); | ||||
|                 ((LoginActivity) requireActivity()).setAdmin(checked); | ||||
|                 item.setChecked(!item.isChecked()); | ||||
|                 item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); | ||||
|                 item.setActionView(new View(requireContext())); | ||||
|                 item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { | ||||
|                     @Override | ||||
|                     public boolean onMenuItemActionExpand(MenuItem item) { | ||||
|                         return false; | ||||
|                     } | ||||
| 
 | ||||
|                     @Override | ||||
|                     public boolean onMenuItemActionCollapse(MenuItem item) { | ||||
|                         return false; | ||||
|                     } | ||||
|                 }); | ||||
|             } | ||||
|             return false; | ||||
|         }); | ||||
|  | @ -230,7 +248,7 @@ public class FragmentLoginMain extends Fragment { | |||
|             Toasty.error(requireActivity(), getString(R.string.client_error), Toast.LENGTH_LONG).show(); | ||||
|         } | ||||
|         if (api == Account.API.MASTODON) { | ||||
|             String scopes = binding.adminScope.isChecked() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES; | ||||
|             String scopes = ((LoginActivity) requireActivity()).requestedAdmin() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES; | ||||
|             AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class); | ||||
|             appsVM.createApp(currentInstance, getString(R.string.app_name), | ||||
|                     Helper.REDIRECT_CONTENT_WEB, | ||||
|  | @ -239,13 +257,13 @@ public class FragmentLoginMain extends Fragment { | |||
|             ).observe(requireActivity(), app -> { | ||||
|                 client_id = app.client_id; | ||||
|                 client_secret = app.client_secret; | ||||
|                 String redirectUrl = MastodonHelper.authorizeURL(currentInstance, client_id, binding.adminScope.isChecked()); | ||||
|                 String redirectUrl = MastodonHelper.authorizeURL(currentInstance, client_id, ((LoginActivity) requireActivity()).requestedAdmin()); | ||||
|                 SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); | ||||
|                 boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true); | ||||
|                 if (embedded_browser) { | ||||
|                     Intent i = new Intent(requireActivity(), WebviewConnectActivity.class); | ||||
|                     i.putExtra("login_url", redirectUrl); | ||||
|                     i.putExtra("requestedAdmin", binding.adminScope.isChecked()); | ||||
|                     i.putExtra("requestedAdmin", ((LoginActivity) requireActivity()).requestedAdmin()); | ||||
|                     startActivity(i); | ||||
|                     requireActivity().finish(); | ||||
|                 } else { | ||||
|  |  | |||
|  | @ -48,14 +48,6 @@ | |||
|             android:imeOptions="actionNext" | ||||
|             android:inputType="textWebEmailAddress" | ||||
|             android:singleLine="true" /> | ||||
| 
 | ||||
|         <com.google.android.material.checkbox.MaterialCheckBox | ||||
|             android:id="@+id/admin_scope" | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:text="@string/admin_scope" | ||||
|             app:buttonTint="@color/cyanea_accent_reference" /> | ||||
| 
 | ||||
|     </com.google.android.material.textfield.TextInputLayout> | ||||
| 
 | ||||
|     <com.google.android.material.button.MaterialButton | ||||
|  |  | |||
|  | @ -21,6 +21,11 @@ | |||
|         android:checkable="true" | ||||
|         android:title="@string/custom_tabs" | ||||
|         app:actionViewClass="android.widget.CheckBox" /> | ||||
|     <item | ||||
|         android:id="@+id/action_request_admin" | ||||
|         android:checkable="true" | ||||
|         android:title="@string/admin_scope" | ||||
|         app:actionViewClass="android.widget.CheckBox" /> | ||||
|     <!-- | ||||
|    <item | ||||
|        android:id="@+id/action_import_data" | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue