2222import com .yangdai .calc .main .toolbox .functions .bmi .BMIActivity ;
2323import com .yangdai .calc .main .toolbox .functions .chinese .ChineseNumberConversionActivity ;
2424import com .yangdai .calc .main .toolbox .functions .programmer .ProgrammerActivity ;
25+ import com .yangdai .calc .main .toolbox .functions .ruler .RulerActivity ;
2526import com .yangdai .calc .main .toolbox .functions .shopping .ShoppingActivity ;
2627import com .yangdai .calc .main .toolbox .functions .algebra .StatisticsActivity ;
2728import com .yangdai .calc .R ;
@@ -48,22 +49,7 @@ public class ToolBoxFragment extends Fragment {
4849 ToolBoxAdapter adapter ;
4950 private List <ToolBoxItem > newData ;
5051 private List <ToolBoxItem > data ;
51- private static final String ORDER = "0/1/2/3/4/5/6/7/8/9/10/11/12/13" ;
5252 boolean isGrid ;
53- private static final int UNIT_ACTIVITY_ID = 0 ;
54- private static final int DATE_RANGE_ACTIVITY_ID = 1 ;
55- private static final int FINANCE_ACTIVITY_ID = 2 ;
56- private static final int COMPASS_ACTIVITY_ID = 3 ;
57- private static final int BMI_ACTIVITY_ID = 4 ;
58- private static final int SHOPPING_ACTIVITY_ID = 5 ;
59- private static final int CURRENCY_ACTIVITY_ID = 6 ;
60- private static final int CHINESE_NUMBER_CONVERSION_ACTIVITY_ID = 7 ;
61- private static final int RELATIONSHIP_ACTIVITY_ID = 8 ;
62- private static final int RANDOM_ACTIVITY_ID = 9 ;
63- private static final int FUNCTION_ACTIVITY_ID = 10 ;
64- private static final int STATISTICS_ACTIVITY_ID = 11 ;
65- private static final int FRACTION_ACTIVITY_ID = 12 ;
66- private static final int PROGRAMMER_ACTIVITY_ID = 13 ;
6753
6854 public ToolBoxFragment () {
6955 }
@@ -77,20 +63,21 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
7763 @ SuppressLint ("UseCompatLoadingForDrawables" )
7864 private List <ToolBoxItem > createToolBoxItems () {
7965 List <ToolBoxItem > items = new ArrayList <>();
80- items .add (new ToolBoxItem (UNIT_ACTIVITY_ID , getString (R .string .UnitsActivity ), getResources ().getDrawable (R .drawable .unit_icon , requireContext ().getTheme ())));
81- items .add (new ToolBoxItem (DATE_RANGE_ACTIVITY_ID , getString (R .string .dateActivity ), getResources ().getDrawable (R .drawable .date_range_icon , requireContext ().getTheme ())));
82- items .add (new ToolBoxItem (FINANCE_ACTIVITY_ID , getString (R .string .financeActivity ), getResources ().getDrawable (R .drawable .finance_icon , requireContext ().getTheme ())));
83- items .add (new ToolBoxItem (COMPASS_ACTIVITY_ID , getString (R .string .compassActivity ), getResources ().getDrawable (R .drawable .compass_icon , requireContext ().getTheme ())));
84- items .add (new ToolBoxItem (BMI_ACTIVITY_ID , getString (R .string .bmiActivity ), getResources ().getDrawable (R .drawable .bmi_icon , requireContext ().getTheme ())));
85- items .add (new ToolBoxItem (SHOPPING_ACTIVITY_ID , getString (R .string .shoppingActivity ), getResources ().getDrawable (R .drawable .shopping_icon , requireContext ().getTheme ())));
86- items .add (new ToolBoxItem (CURRENCY_ACTIVITY_ID , getString (R .string .exchangeActivity ), getResources ().getDrawable (R .drawable .currency_exchange_icon , requireContext ().getTheme ())));
87- items .add (new ToolBoxItem (CHINESE_NUMBER_CONVERSION_ACTIVITY_ID , getString (R .string .chineseNumberConverter ), getResources ().getDrawable (R .drawable .chinese_number_icon , requireContext ().getTheme ())));
88- items .add (new ToolBoxItem (RELATIONSHIP_ACTIVITY_ID , getString (R .string .relationshipActivity ), getResources ().getDrawable (R .drawable .relation_icon , requireContext ().getTheme ())));
89- items .add (new ToolBoxItem (RANDOM_ACTIVITY_ID , getString (R .string .randomActivity ), getResources ().getDrawable (R .drawable .random_number_icon , requireContext ().getTheme ())));
90- items .add (new ToolBoxItem (FUNCTION_ACTIVITY_ID , getString (R .string .EquationActivity ), getResources ().getDrawable (R .drawable .functions_icon , requireContext ().getTheme ())));
91- items .add (new ToolBoxItem (STATISTICS_ACTIVITY_ID , getString (R .string .statisticActivity ), getResources ().getDrawable (R .drawable .statistics_icon , requireContext ().getTheme ())));
92- items .add (new ToolBoxItem (FRACTION_ACTIVITY_ID , getString (R .string .numberConvert ), getResources ().getDrawable (R .drawable .fraction , requireContext ().getTheme ())));
93- items .add (new ToolBoxItem (PROGRAMMER_ACTIVITY_ID , getString (R .string .programmer ), getResources ().getDrawable (R .drawable .binary_icon , requireContext ().getTheme ())));
66+ items .add (new ToolBoxItem (Constants .UNIT_ACTIVITY_ID , getString (R .string .UnitsActivity ), getResources ().getDrawable (R .drawable .unit_icon , requireContext ().getTheme ())));
67+ items .add (new ToolBoxItem (Constants .DATE_RANGE_ACTIVITY_ID , getString (R .string .dateActivity ), getResources ().getDrawable (R .drawable .date_range_icon , requireContext ().getTheme ())));
68+ items .add (new ToolBoxItem (Constants .FINANCE_ACTIVITY_ID , getString (R .string .financeActivity ), getResources ().getDrawable (R .drawable .finance_icon , requireContext ().getTheme ())));
69+ items .add (new ToolBoxItem (Constants .COMPASS_ACTIVITY_ID , getString (R .string .compassActivity ), getResources ().getDrawable (R .drawable .compass_icon , requireContext ().getTheme ())));
70+ items .add (new ToolBoxItem (Constants .BMI_ACTIVITY_ID , getString (R .string .bmiActivity ), getResources ().getDrawable (R .drawable .bmi_icon , requireContext ().getTheme ())));
71+ items .add (new ToolBoxItem (Constants .SHOPPING_ACTIVITY_ID , getString (R .string .shoppingActivity ), getResources ().getDrawable (R .drawable .shopping_icon , requireContext ().getTheme ())));
72+ items .add (new ToolBoxItem (Constants .CURRENCY_ACTIVITY_ID , getString (R .string .exchangeActivity ), getResources ().getDrawable (R .drawable .currency_exchange_icon , requireContext ().getTheme ())));
73+ items .add (new ToolBoxItem (Constants .CHINESE_NUMBER_CONVERSION_ACTIVITY_ID , getString (R .string .chineseNumberConverter ), getResources ().getDrawable (R .drawable .chinese_number_icon , requireContext ().getTheme ())));
74+ items .add (new ToolBoxItem (Constants .RELATIONSHIP_ACTIVITY_ID , getString (R .string .relationshipActivity ), getResources ().getDrawable (R .drawable .relation_icon , requireContext ().getTheme ())));
75+ items .add (new ToolBoxItem (Constants .RANDOM_ACTIVITY_ID , getString (R .string .randomActivity ), getResources ().getDrawable (R .drawable .random_number_icon , requireContext ().getTheme ())));
76+ items .add (new ToolBoxItem (Constants .FUNCTION_ACTIVITY_ID , getString (R .string .EquationActivity ), getResources ().getDrawable (R .drawable .functions_icon , requireContext ().getTheme ())));
77+ items .add (new ToolBoxItem (Constants .STATISTICS_ACTIVITY_ID , getString (R .string .statisticActivity ), getResources ().getDrawable (R .drawable .statistics_icon , requireContext ().getTheme ())));
78+ items .add (new ToolBoxItem (Constants .FRACTION_ACTIVITY_ID , getString (R .string .numberConvert ), getResources ().getDrawable (R .drawable .fraction , requireContext ().getTheme ())));
79+ items .add (new ToolBoxItem (Constants .PROGRAMMER_ACTIVITY_ID , getString (R .string .programmer ), getResources ().getDrawable (R .drawable .binary_icon , requireContext ().getTheme ())));
80+ items .add (new ToolBoxItem (Constants .RULER_ACTIVITY_ID , getString (R .string .ruler ), getResources ().getDrawable (R .drawable .ruler_icon , requireContext ().getTheme ())));
9481 return items ;
9582 }
9683
@@ -114,7 +101,7 @@ public void onViewCreated(@NonNull View notes, @Nullable Bundle savedInstanceSta
114101 isGrid = bundle .getBoolean ("GridLayout" , true );
115102 updateRecycleView (isGrid );
116103 });
117- String order = sharedPreferences .getString ("order" , ORDER );
104+ String order = sharedPreferences .getString ("order" , Constants . ORDER );
118105 List <String > orderList = new ArrayList <>(Arrays .asList (order .split ("/" )));
119106 if (orderList .size () < data .size ()) {
120107 int oLength = orderList .size ();
@@ -126,9 +113,9 @@ public void onViewCreated(@NonNull View notes, @Nullable Bundle savedInstanceSta
126113 editor .putString ("order" , orderString );
127114 editor .apply ();
128115 } else if (orderList .size () > data .size ()) {
129- orderList = new ArrayList <>(Arrays .asList (ORDER .split ("/" )));
116+ orderList = new ArrayList <>(Arrays .asList (Constants . ORDER .split ("/" )));
130117 SharedPreferences .Editor editor = sharedPreferences .edit ();
131- editor .putString ("order" , ORDER );
118+ editor .putString ("order" , Constants . ORDER );
132119 editor .apply ();
133120 }
134121
@@ -181,42 +168,65 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
181168 };
182169 }
183170
184-
185171 private void updateRecycleView (boolean isGrid ) {
186- adapter = new ToolBoxAdapter (newData , isGrid , (item ) -> {
187- int itemId = item .id ();
188- switch (itemId ) {
189- case UNIT_ACTIVITY_ID ->
190- startActivity (new Intent (getContext (), UnitActivity .class ));
191- case DATE_RANGE_ACTIVITY_ID ->
192- startActivity (new Intent (getContext (), DateRangeActivity .class ));
193- case FINANCE_ACTIVITY_ID ->
194- startActivity (new Intent (getContext (), FinanceActivity .class ));
195- case COMPASS_ACTIVITY_ID -> startActivity (new Intent (getContext (), Compass .class ));
196- case BMI_ACTIVITY_ID -> startActivity (new Intent (getContext (), BMIActivity .class ));
197- case SHOPPING_ACTIVITY_ID ->
198- startActivity (new Intent (getContext (), ShoppingActivity .class ));
199- case CURRENCY_ACTIVITY_ID ->
200- startActivity (new Intent (getContext (), CurrencyActivity .class ));
201- case CHINESE_NUMBER_CONVERSION_ACTIVITY_ID ->
202- startActivity (new Intent (getContext (), ChineseNumberConversionActivity .class ));
203- case RELATIONSHIP_ACTIVITY_ID ->
204- startActivity (new Intent (getContext (), RelationshipActivity .class ));
205- case RANDOM_ACTIVITY_ID ->
206- startActivity (new Intent (getContext (), RandomNumberActivity .class ));
207- case FUNCTION_ACTIVITY_ID ->
208- startActivity (new Intent (getContext (), EquationActivity .class ));
209- case STATISTICS_ACTIVITY_ID ->
210- startActivity (new Intent (getContext (), StatisticsActivity .class ));
211- case FRACTION_ACTIVITY_ID ->
212- startActivity (new Intent (getContext (), FractionActivity .class ));
213- case PROGRAMMER_ACTIVITY_ID ->
214- startActivity (new Intent (getContext (), ProgrammerActivity .class ));
215- default -> {
216- }
217- }
218- });
172+ adapter = new ToolBoxAdapter (newData , isGrid , this ::startActivityById );
219173 recyclerView .setLayoutManager (isGrid ? new GridLayoutManager (getContext (), 3 ) : new LinearLayoutManager (getContext ()));
220174 recyclerView .setAdapter (adapter );
221175 }
176+
177+ private void startActivityById (ToolBoxItem item ) {
178+ Intent intent = null ;
179+ switch (item .id ()) {
180+ case Constants .UNIT_ACTIVITY_ID ->
181+ intent = new Intent (getContext (), UnitActivity .class );
182+ case Constants .DATE_RANGE_ACTIVITY_ID ->
183+ intent = new Intent (getContext (), DateRangeActivity .class );
184+ case Constants .FINANCE_ACTIVITY_ID ->
185+ intent = new Intent (getContext (), FinanceActivity .class );
186+ case Constants .COMPASS_ACTIVITY_ID -> intent = new Intent (getContext (), Compass .class );
187+ case Constants .BMI_ACTIVITY_ID -> intent = new Intent (getContext (), BMIActivity .class );
188+ case Constants .SHOPPING_ACTIVITY_ID ->
189+ intent = new Intent (getContext (), ShoppingActivity .class );
190+ case Constants .CURRENCY_ACTIVITY_ID ->
191+ intent = new Intent (getContext (), CurrencyActivity .class );
192+ case Constants .CHINESE_NUMBER_CONVERSION_ACTIVITY_ID ->
193+ intent = new Intent (getContext (), ChineseNumberConversionActivity .class );
194+ case Constants .RELATIONSHIP_ACTIVITY_ID ->
195+ intent = new Intent (getContext (), RelationshipActivity .class );
196+ case Constants .RANDOM_ACTIVITY_ID ->
197+ intent = new Intent (getContext (), RandomNumberActivity .class );
198+ case Constants .FUNCTION_ACTIVITY_ID ->
199+ intent = new Intent (getContext (), EquationActivity .class );
200+ case Constants .STATISTICS_ACTIVITY_ID ->
201+ intent = new Intent (getContext (), StatisticsActivity .class );
202+ case Constants .FRACTION_ACTIVITY_ID ->
203+ intent = new Intent (getContext (), FractionActivity .class );
204+ case Constants .PROGRAMMER_ACTIVITY_ID ->
205+ intent = new Intent (getContext (), ProgrammerActivity .class );
206+ case Constants .RULER_ACTIVITY_ID ->
207+ intent = new Intent (getContext (), RulerActivity .class );
208+ }
209+ if (intent != null ) {
210+ startActivity (intent );
211+ }
212+ }
213+
214+ private static class Constants {
215+ public static final String ORDER = "0/1/2/3/4/5/6/7/8/9/10/11/12/13/14" ;
216+ public static final int UNIT_ACTIVITY_ID = 0 ;
217+ public static final int DATE_RANGE_ACTIVITY_ID = 1 ;
218+ public static final int FINANCE_ACTIVITY_ID = 2 ;
219+ public static final int COMPASS_ACTIVITY_ID = 3 ;
220+ public static final int BMI_ACTIVITY_ID = 4 ;
221+ public static final int SHOPPING_ACTIVITY_ID = 5 ;
222+ public static final int CURRENCY_ACTIVITY_ID = 6 ;
223+ public static final int CHINESE_NUMBER_CONVERSION_ACTIVITY_ID = 7 ;
224+ public static final int RELATIONSHIP_ACTIVITY_ID = 8 ;
225+ public static final int RANDOM_ACTIVITY_ID = 9 ;
226+ public static final int FUNCTION_ACTIVITY_ID = 10 ;
227+ public static final int STATISTICS_ACTIVITY_ID = 11 ;
228+ public static final int FRACTION_ACTIVITY_ID = 12 ;
229+ public static final int PROGRAMMER_ACTIVITY_ID = 13 ;
230+ public static final int RULER_ACTIVITY_ID = 14 ;
231+ }
222232}
0 commit comments