mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Add back custom tabs
This commit is contained in:
		
							parent
							
								
									a6c17512cc
								
							
						
					
					
						commit
						7ce644e922
					
				
					 6 changed files with 78 additions and 36 deletions
				
			
		|  | @ -76,6 +76,8 @@ import androidx.annotation.IdRes; | ||||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||||
| import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||||
| import androidx.appcompat.app.AlertDialog; | import androidx.appcompat.app.AlertDialog; | ||||||
|  | import androidx.browser.customtabs.CustomTabColorSchemeParams; | ||||||
|  | import androidx.browser.customtabs.CustomTabsIntent; | ||||||
| import androidx.core.app.ActivityOptionsCompat; | import androidx.core.app.ActivityOptionsCompat; | ||||||
| import androidx.core.app.NotificationCompat; | import androidx.core.app.NotificationCompat; | ||||||
| import androidx.core.app.NotificationManagerCompat; | import androidx.core.app.NotificationManagerCompat; | ||||||
|  | @ -646,16 +648,29 @@ public class Helper { | ||||||
|         if (url == null) { |         if (url == null) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         Intent intent = new Intent(Intent.ACTION_VIEW); |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); | ||||||
|         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |         boolean customTab = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOM_TABS), true); | ||||||
|         if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://") && !url.toLowerCase().startsWith("gemini://")) { |         if (customTab) { | ||||||
|             url = "http://" + url; |             CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); | ||||||
|         } |             int colorInt = ThemeHelper.getAttColor(context, R.attr.statusBar); | ||||||
|         intent.setData(Uri.parse(url)); |             CustomTabColorSchemeParams defaultColors = new CustomTabColorSchemeParams.Builder() | ||||||
|         try { |                     .setToolbarColor(colorInt) | ||||||
|             context.startActivity(intent); |                     .build(); | ||||||
|         } catch (Exception e) { |             builder.setDefaultColorSchemeParams(defaultColors); | ||||||
|             Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); |             CustomTabsIntent customTabsIntent = builder.build(); | ||||||
|  |             customTabsIntent.launchUrl(context, Uri.parse(url)); | ||||||
|  |         } else { | ||||||
|  |             Intent intent = new Intent(Intent.ACTION_VIEW); | ||||||
|  |             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||||
|  |             if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://") && !url.toLowerCase().startsWith("gemini://")) { | ||||||
|  |                 url = "http://" + url; | ||||||
|  |             } | ||||||
|  |             intent.setData(Uri.parse(url)); | ||||||
|  |             try { | ||||||
|  |                 context.startActivity(intent); | ||||||
|  |             } catch (Exception e) { | ||||||
|  |                 Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -25,6 +25,7 @@ import static app.fedilab.android.activities.LoginActivity.softwareLogin; | ||||||
| 
 | 
 | ||||||
| import android.Manifest; | import android.Manifest; | ||||||
| import android.content.Intent; | import android.content.Intent; | ||||||
|  | import android.content.SharedPreferences; | ||||||
| import android.content.pm.PackageManager; | import android.content.pm.PackageManager; | ||||||
| import android.net.Uri; | import android.net.Uri; | ||||||
| import android.os.Build; | import android.os.Build; | ||||||
|  | @ -43,9 +44,12 @@ import androidx.activity.result.ActivityResultLauncher; | ||||||
| import androidx.activity.result.contract.ActivityResultContracts; | import androidx.activity.result.contract.ActivityResultContracts; | ||||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||||
| import androidx.appcompat.widget.PopupMenu; | import androidx.appcompat.widget.PopupMenu; | ||||||
|  | import androidx.browser.customtabs.CustomTabColorSchemeParams; | ||||||
|  | import androidx.browser.customtabs.CustomTabsIntent; | ||||||
| import androidx.core.app.ActivityCompat; | import androidx.core.app.ActivityCompat; | ||||||
| import androidx.fragment.app.Fragment; | import androidx.fragment.app.Fragment; | ||||||
| import androidx.lifecycle.ViewModelProvider; | import androidx.lifecycle.ViewModelProvider; | ||||||
|  | import androidx.preference.PreferenceManager; | ||||||
| 
 | 
 | ||||||
| import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||||
| import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||||
|  | @ -60,6 +64,7 @@ import app.fedilab.android.mastodon.client.entities.app.Account; | ||||||
| import app.fedilab.android.mastodon.client.entities.app.InstanceSocial; | import app.fedilab.android.mastodon.client.entities.app.InstanceSocial; | ||||||
| import app.fedilab.android.mastodon.helper.Helper; | import app.fedilab.android.mastodon.helper.Helper; | ||||||
| import app.fedilab.android.mastodon.helper.MastodonHelper; | import app.fedilab.android.mastodon.helper.MastodonHelper; | ||||||
|  | import app.fedilab.android.mastodon.helper.ThemeHelper; | ||||||
| import app.fedilab.android.mastodon.helper.ZipHelper; | import app.fedilab.android.mastodon.helper.ZipHelper; | ||||||
| import app.fedilab.android.mastodon.viewmodel.mastodon.AppsVM; | import app.fedilab.android.mastodon.viewmodel.mastodon.AppsVM; | ||||||
| import app.fedilab.android.mastodon.viewmodel.mastodon.InstanceSocialVM; | import app.fedilab.android.mastodon.viewmodel.mastodon.InstanceSocialVM; | ||||||
|  | @ -214,6 +219,10 @@ public class FragmentLoginMain extends Fragment { | ||||||
|         menuInflater.inflate(R.menu.main_login, popupMenu.getMenu()); |         menuInflater.inflate(R.menu.main_login, popupMenu.getMenu()); | ||||||
|         MenuItem adminTabItem = popupMenu.getMenu().findItem(R.id.action_request_admin); |         MenuItem adminTabItem = popupMenu.getMenu().findItem(R.id.action_request_admin); | ||||||
|         adminTabItem.setChecked(requestedAdmin); |         adminTabItem.setChecked(requestedAdmin); | ||||||
|  |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); | ||||||
|  |         boolean customTab = sharedpreferences.getBoolean(getString(R.string.SET_CUSTOM_TABS), true); | ||||||
|  |         popupMenu.getMenu().findItem(R.id.action_custom_tabs).setChecked(customTab); | ||||||
|  | 
 | ||||||
|         popupMenu.setOnMenuItemClickListener(item -> { |         popupMenu.setOnMenuItemClickListener(item -> { | ||||||
|             int itemId = item.getItemId(); |             int itemId = item.getItemId(); | ||||||
|             if (itemId == R.id.action_proxy) { |             if (itemId == R.id.action_proxy) { | ||||||
|  | @ -242,6 +251,13 @@ public class FragmentLoginMain extends Fragment { | ||||||
|                 } else { |                 } else { | ||||||
|                     proceed(); |                     proceed(); | ||||||
|                 } |                 } | ||||||
|  |             } else if (itemId == R.id.action_custom_tabs) { | ||||||
|  |                 boolean newValue = !item.isChecked(); | ||||||
|  |                 item.setChecked(newValue); | ||||||
|  |                 SharedPreferences.Editor editor = sharedpreferences.edit(); | ||||||
|  |                 editor.putBoolean(getString(R.string.SET_CUSTOM_TABS), newValue); | ||||||
|  |                 editor.apply(); | ||||||
|  |                 return false; | ||||||
|             } |             } | ||||||
|             return false; |             return false; | ||||||
|         }); |         }); | ||||||
|  | @ -291,13 +307,26 @@ public class FragmentLoginMain extends Fragment { | ||||||
|                 client_idLogin = app.client_id; |                 client_idLogin = app.client_id; | ||||||
|                 client_secretLogin = app.client_secret; |                 client_secretLogin = app.client_secret; | ||||||
|                 String redirectUrl = MastodonHelper.authorizeURL(currentInstanceLogin, client_idLogin, requestedAdmin); |                 String redirectUrl = MastodonHelper.authorizeURL(currentInstanceLogin, client_idLogin, requestedAdmin); | ||||||
|                 Intent intent = new Intent(Intent.ACTION_VIEW); |                 SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); | ||||||
|                 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |                 boolean customTab = sharedpreferences.getBoolean(getString(R.string.SET_CUSTOM_TABS), true); | ||||||
|                 intent.setData(Uri.parse(redirectUrl)); |                 if (customTab) { | ||||||
|                 try { |                     CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); | ||||||
|                     startActivity(intent); |                     int colorInt = ThemeHelper.getAttColor(requireActivity(), R.attr.statusBar); | ||||||
|                 } catch (Exception e) { |                     CustomTabColorSchemeParams defaultColors = new CustomTabColorSchemeParams.Builder() | ||||||
|                     Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show(); |                             .setToolbarColor(colorInt) | ||||||
|  |                             .build(); | ||||||
|  |                     builder.setDefaultColorSchemeParams(defaultColors); | ||||||
|  |                     CustomTabsIntent customTabsIntent = builder.build(); | ||||||
|  |                     customTabsIntent.launchUrl(requireActivity(), Uri.parse(redirectUrl)); | ||||||
|  |                 } else { | ||||||
|  |                     Intent intent = new Intent(Intent.ACTION_VIEW); | ||||||
|  |                     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||||
|  |                     intent.setData(Uri.parse(redirectUrl)); | ||||||
|  |                     try { | ||||||
|  |                         startActivity(intent); | ||||||
|  |                     } catch (Exception e) { | ||||||
|  |                         Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show(); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|             } else { |             } else { | ||||||
|                 Toasty.error(requireActivity(), getString(R.string.client_error), Toasty.LENGTH_SHORT).show(); |                 Toasty.error(requireActivity(), getString(R.string.client_error), Toasty.LENGTH_SHORT).show(); | ||||||
|  |  | ||||||
|  | @ -1,17 +1,7 @@ | ||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <menu xmlns:android="http://schemas.android.com/apk/res/android" | <menu 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"> | ||||||
|     <!-- |  | ||||||
|      <item |  | ||||||
|          android:id="@+id/action_about" |  | ||||||
|          android:title="@string/action_about" |  | ||||||
|          app:showAsAction="never" /> |  | ||||||
| 
 | 
 | ||||||
|      <item |  | ||||||
|          android:id="@+id/action_privacy" |  | ||||||
|          android:title="@string/action_privacy" |  | ||||||
|          app:showAsAction="never" /> |  | ||||||
|           --> |  | ||||||
|     <item |     <item | ||||||
|         android:id="@+id/action_proxy" |         android:id="@+id/action_proxy" | ||||||
|         android:title="@string/proxy_set" |         android:title="@string/proxy_set" | ||||||
|  | @ -27,11 +17,10 @@ | ||||||
|         android:title="@string/import_data" |         android:title="@string/import_data" | ||||||
|         app:showAsAction="never" /> |         app:showAsAction="never" /> | ||||||
| 
 | 
 | ||||||
|     <!-- |     <item | ||||||
|  <item |         android:id="@+id/action_custom_tabs" | ||||||
|      android:id="@+id/action_provider" |         android:checkable="true" | ||||||
|      android:checkable="true" |         android:title="@string/custom_tabs" | ||||||
|      android:title="@string/set_security_provider" |         app:actionViewClass="android.widget.CheckBox" /> | ||||||
|      app:actionViewClass="android.widget.CheckBox" /> | 
 | ||||||
|      --> |  | ||||||
| </menu> | </menu> | ||||||
|  |  | ||||||
|  | @ -1509,6 +1509,7 @@ | ||||||
|     <string name="SET_NITTER_HOST" translatable="false">SET_NITTER_HOST</string> |     <string name="SET_NITTER_HOST" translatable="false">SET_NITTER_HOST</string> | ||||||
|     <string name="DEFAULT_NITTER_HOST" translatable="false">nitter.net</string> |     <string name="DEFAULT_NITTER_HOST" translatable="false">nitter.net</string> | ||||||
|     <string name="SET_USE_CACHE" translatable="false">SET_USE_CACHE</string> |     <string name="SET_USE_CACHE" translatable="false">SET_USE_CACHE</string> | ||||||
|  |     <string name="SET_CUSTOM_TABS" translatable="false">SET_CUSTOM_TABS</string> | ||||||
|     <string name="SET_BIBLIOGRAM" translatable="false">SET_BIBLIOGRAM</string> |     <string name="SET_BIBLIOGRAM" translatable="false">SET_BIBLIOGRAM</string> | ||||||
|     <string name="SET_BIBLIOGRAM_HOST" translatable="false">SET_BIBLIOGRAM_HOST</string> |     <string name="SET_BIBLIOGRAM_HOST" translatable="false">SET_BIBLIOGRAM_HOST</string> | ||||||
|     <string name="DEFAULT_BIBLIOGRAM_HOST" translatable="false">bibliogram.art</string> |     <string name="DEFAULT_BIBLIOGRAM_HOST" translatable="false">bibliogram.art</string> | ||||||
|  |  | ||||||
|  | @ -69,6 +69,13 @@ | ||||||
|         app:summary="@string/set_use_cache_indication" |         app:summary="@string/set_use_cache_indication" | ||||||
|         app:title="@string/set_use_cache" /> |         app:title="@string/set_use_cache" /> | ||||||
| 
 | 
 | ||||||
|  |     <SwitchPreferenceCompat | ||||||
|  |         app:defaultValue="true" | ||||||
|  |         app:iconSpaceReserved="false" | ||||||
|  |         app:key="@string/SET_CUSTOM_TABS" | ||||||
|  |         app:singleLineTitle="false" | ||||||
|  |         app:title="@string/custom_tabs" /> | ||||||
|  | 
 | ||||||
|     <SwitchPreferenceCompat |     <SwitchPreferenceCompat | ||||||
|         app:defaultValue="false" |         app:defaultValue="false" | ||||||
|         app:iconSpaceReserved="false" |         app:iconSpaceReserved="false" | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| Added: | Added: | ||||||
| - Camel case tags (automatically recorded when composing) | - Support camel case tags (automatically recorded when composing) | ||||||
| - Manage tags (add new ones) when composing (main top right menu) | - Manage tags when composing (top right menu) | ||||||
|  | - Custom tabs (default: enabled) | ||||||
| 
 | 
 | ||||||
| Changed: | Changed: | ||||||
| - Media heights now use the screen size | - Media heights now use the screen size | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue