1717package org .microg .tools .ui ;
1818
1919import android .content .Context ;
20+ import android .content .Intent ;
2021import android .content .pm .PackageManager ;
2122import android .graphics .drawable .Drawable ;
23+ import android .net .Uri ;
2224import android .os .Bundle ;
2325import android .text .TextUtils ;
2426import android .view .LayoutInflater ;
2527import android .view .View ;
2628import android .view .ViewGroup ;
2729import android .widget .ArrayAdapter ;
28- import android .widget .Button ;
2930import android .widget .ImageView ;
3031import android .widget .TextView ;
3132
@@ -51,31 +52,31 @@ public abstract class AbstractAboutFragment extends Fragment {
5152
5253 protected abstract void collectLibraries (List <Library > libraries );
5354
54- public static Drawable getIcon (Context context ) {
55- try {
56- PackageManager pm = context .getPackageManager ();
57- return Objects .requireNonNull (pm .getPackageInfo (context .getPackageName (), 0 ).applicationInfo ).loadIcon (pm );
58- } catch (PackageManager .NameNotFoundException e ) {
59- // Never happens, self package always exists!
60- throw new RuntimeException (e );
61- }
62- }
63-
64- public static String getAppName (Context context ) {
65- try {
66- PackageManager pm = context .getPackageManager ();
67- CharSequence label = Objects .requireNonNull (pm .getPackageInfo (context .getPackageName (), 0 ).applicationInfo ).loadLabel (pm );
68- if (TextUtils .isEmpty (label )) return context .getPackageName ();
69- return label .toString ().trim ();
70- } catch (PackageManager .NameNotFoundException e ) {
71- // Never happens, self package always exists!
72- throw new RuntimeException (e );
73- }
74- }
75-
76- protected String getAppName () {
77- return getAppName (requireContext ());
78- }
55+ // public static Drawable getIcon(Context context) {
56+ // try {
57+ // PackageManager pm = context.getPackageManager();
58+ // return Objects.requireNonNull(pm.getPackageInfo(context.getPackageName(), 0).applicationInfo).loadIcon(pm);
59+ // } catch (PackageManager.NameNotFoundException e) {
60+ // // Never happens, self package always exists!
61+ // throw new RuntimeException(e);
62+ // }
63+ // }
64+ //
65+ // public static String getAppName(Context context) {
66+ // try {
67+ // PackageManager pm = context.getPackageManager();
68+ // CharSequence label = Objects.requireNonNull(pm.getPackageInfo(context.getPackageName(), 0).applicationInfo).loadLabel(pm);
69+ // if (TextUtils.isEmpty(label)) return context.getPackageName();
70+ // return label.toString().trim();
71+ // } catch (PackageManager.NameNotFoundException e) {
72+ // // Never happens, self package always exists!
73+ // throw new RuntimeException(e);
74+ // }
75+ // }
76+
77+ // protected String getAppName() {
78+ // return getAppName(requireContext());
79+ // }
7980
8081 public static String getLibVersion (String packageName ) {
8182 try {
@@ -116,54 +117,81 @@ protected String getSummary() {
116117
117118 @ Nullable
118119 @ Override
119- public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
120+ public View onCreateView (@ NonNull LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
120121 View aboutRoot = inflater .inflate (R .layout .about_root , container , false );
121122
122- ((ImageView ) aboutRoot .findViewById (android .R .id .icon )).setImageDrawable (getIcon (requireContext ()));
123- ((TextView ) aboutRoot .findViewById (android .R .id .title )).setText (getAppName ());
124- ((TextView ) aboutRoot .findViewById (R .id .about_version )).setText (getString (R .string .about_version_str , getSelfVersion ()));
123+ ViewGroup appCardContainer = aboutRoot .findViewById (R .id .app_card_container );
124+ if (appCardContainer != null ) {
125+ View appCard = inflater .inflate (R .layout .about_app , appCardContainer , true );
126+ // ((ImageView) appCard.findViewById(R.id.app_icon)).setImageDrawable(getIcon(requireContext()));
127+ // ((TextView) appCard.findViewById(R.id.app_title)).setText(getAppName());
128+ ((TextView ) appCard .findViewById (R .id .app_version )).setText (getSelfVersion ());
129+
130+ appCard .findViewById (R .id .app_check_updates ).setOnClickListener (v -> {
131+ new UpdateChecker (requireContext ()).checkForUpdates (v , () -> {
132+ });
133+ });
125134
126- String summary = getSummary ();
127- if (summary != null ) {
128- ((TextView ) aboutRoot .findViewById (android .R .id .summary )).setText (summary );
129- aboutRoot .findViewById (android .R .id .summary ).setVisibility (View .VISIBLE );
135+ View appInfo = appCard .findViewById (R .id .app_info );
136+ if (appInfo != null ) {
137+ appInfo .setOnClickListener (v -> {
138+ Intent intent = new Intent (android .provider .Settings .ACTION_APPLICATION_DETAILS_SETTINGS );
139+ intent .setData (Uri .parse ("package:" + requireContext ().getPackageName ()));
140+ try {
141+ startActivity (intent );
142+ } catch (Exception ignored ) {
143+ }
144+ });
145+ }
146+ }
147+
148+ ViewGroup morpheCardContainer = aboutRoot .findViewById (R .id .morphe_card_container );
149+ if (morpheCardContainer != null ) {
150+ View morpheCard = inflater .inflate (R .layout .about_morphe , morpheCardContainer , true );
151+
152+ morpheCard .findViewById (R .id .morphe_github ).setOnClickListener (v -> openUrl ("https://github.com/MorpheApp" ));
153+ morpheCard .findViewById (R .id .morphe_x ).setOnClickListener (v -> openUrl ("https://twitter.com/MorpheApp" ));
154+ morpheCard .findViewById (R .id .morphe_reddit ).setOnClickListener (v -> openUrl ("https://www.reddit.com/r/MorpheApp" ));
155+ morpheCard .findViewById (R .id .morphe_website ).setOnClickListener (v -> openUrl ("https://morphe.software/" ));
130156 }
131157
132158 List <Library > libraries = new ArrayList <>();
133159 collectLibraries (libraries );
134160 Collections .sort (libraries );
135161
136162 ViewGroup libraryContainer = aboutRoot .findViewById (R .id .library_container );
137- for (int i = 0 ; i < libraries .size (); i ++) {
138- Library library = libraries .get (i );
163+ if (libraryContainer != null ) {
164+ for (int i = 0 ; i < libraries .size (); i ++) {
165+ Library library = libraries .get (i );
166+ View libraryView = inflater .inflate (R .layout .library_item , libraryContainer , false );
139167
140- View libraryView = inflater .inflate (R .layout .library_item , libraryContainer , false );
168+ TextView title = libraryView .findViewById (android .R .id .text1 );
169+ TextView subtitle = libraryView .findViewById (android .R .id .text2 );
141170
142- TextView title = libraryView . findViewById ( android . R . id . text1 );
143- TextView subtitle = libraryView . findViewById ( android . R . id . text2 );
171+ title . setText ( getString ( R . string . about_name_version_str , library . name , getLibVersion ( library . packageName )) );
172+ subtitle . setText ( library . copyright != null ? library . copyright : getString ( R . string . about_default_license ) );
144173
145- title .setText (getString (R .string .about_name_version_str , library .name , getLibVersion (library .packageName )));
146- subtitle .setText (library .copyright != null ? library .copyright : getString (R .string .about_default_license ));
174+ com .google .android .material .listitem .ListItemLayout listItemLayout = libraryView .findViewById (R .id .list_item_library );
175+ if (listItemLayout != null ) {
176+ listItemLayout .updateAppearance (i , libraries .size ());
177+ }
147178
148- com .google .android .material .listitem .ListItemLayout listItemLayout = libraryView .findViewById (R .id .list_item_library );
149- listItemLayout .updateAppearance (i , libraries .size ());
150-
151- libraryContainer .addView (libraryView );
179+ libraryContainer .addView (libraryView );
180+ }
152181 }
153182
154- Button btnCheckUpdates = aboutRoot .findViewById (R .id .btnCheckUpdates );
155- btnCheckUpdates .setOnClickListener (v -> {
156- Context context = getContext ();
157- if (context == null ) return ;
158- UpdateChecker updateChecker = new UpdateChecker (context );
159- updateChecker .checkForUpdates (v , () -> {
160- });
161- });
162183 return aboutRoot ;
163184 }
164185
165- private class LibraryAdapter extends ArrayAdapter <Library > {
186+ private void openUrl (String url ) {
187+ try {
188+ Intent intent = new Intent (Intent .ACTION_VIEW , Uri .parse (url ));
189+ startActivity (intent );
190+ } catch (Exception ignored ) {
191+ }
192+ }
166193
194+ private class LibraryAdapter extends ArrayAdapter <Library > {
167195 public LibraryAdapter (Context context , Library [] libraries ) {
168196 super (context , android .R .layout .simple_list_item_2 , android .R .id .text1 , libraries );
169197 }
@@ -178,10 +206,11 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
178206 }
179207 }
180208
209+ @ SuppressWarnings ("ClassCanBeRecord" )
181210 protected static class Library implements Comparable <Library > {
182- private final String packageName ;
183- private final String name ;
184- private final String copyright ;
211+ public final String packageName ;
212+ public final String name ;
213+ public final String copyright ;
185214
186215 public Library (String packageName , String name , String copyright ) {
187216 this .packageName = packageName ;
0 commit comments