1515import in .hridayan .ashell .BuildConfig ;
1616import in .hridayan .ashell .R ;
1717import in .hridayan .ashell .config .Preferences ;
18+ import in .hridayan .ashell .ui .dialogs .FeedbackDialogs ;
1819import in .hridayan .ashell .utils .AppUpdater ;
1920import in .hridayan .ashell .utils .HapticUtils ;
2021
2122public class UpdateCheckerBottomSheet {
2223
23- private final Activity activity ;
24- private final Context context ;
25- private BottomSheetDialog bottomSheetDialog ;
26- private View bottomSheetView ;
27-
28- private MaterialTextView currentVersionTextView ;
29- private MaterialTextView latestVersionTextView ;
30- private MaterialTextView descriptionTextView ;
31- private MaterialButton downloadButton ;
32- private MaterialButton cancelButton ;
33- private LinearProgressIndicator progressBar ;
34- private LottieAnimationView loadingDots ;
35- private FrameLayout progressBarLayout ;
36-
37- /**
38- * Constructor to initialize the Update Checker Bottom Sheet.
39- *
40- * @param activity The activity context.
41- * @param context The application context.
42- */
43- public UpdateCheckerBottomSheet (@ NonNull Activity activity , @ NonNull Context context ) {
44- this .activity = activity ;
45- this .context = context ;
46- initializeBottomSheet ();
47- }
48-
49- /**
50- * Initializes the bottom sheet dialog and its UI components.
51- */
52- private void initializeBottomSheet () {
53- bottomSheetDialog = new BottomSheetDialog (activity );
54- bottomSheetView = LayoutInflater .from (activity ).inflate (R .layout .bottom_sheet_update_checker , null );
55- bottomSheetDialog .setContentView (bottomSheetView );
56-
57- // Initialize UI components
58- progressBarLayout = bottomSheetView .findViewById (R .id .progressBarLayout );
59- currentVersionTextView = bottomSheetView .findViewById (R .id .current_version );
60- latestVersionTextView = bottomSheetView .findViewById (R .id .latest_version );
61- descriptionTextView = bottomSheetView .findViewById (R .id .body );
62- downloadButton = bottomSheetView .findViewById (R .id .download_button );
63- cancelButton = bottomSheetView .findViewById (R .id .cancel_button );
64- progressBar = bottomSheetView .findViewById (R .id .download_progress );
65- loadingDots = bottomSheetView .findViewById (R .id .loading_animation );
66-
67- adjustProgressBarLayout ();
68- setUpButtonListeners ();
69- }
70-
71- /**
72- * Adjusts the progress bar layout to maintain height consistency.
73- */
74- private void adjustProgressBarLayout () {
75- progressBarLayout .post (() -> {
76- int currentHeight = progressBarLayout .getHeight ();
77- progressBarLayout .setMinimumHeight (currentHeight );
78- ViewGroup .LayoutParams params = progressBarLayout .getLayoutParams ();
79- params .height = currentHeight ;
80- progressBarLayout .setLayoutParams (params );
24+ private final Activity activity ;
25+ private final Context context ;
26+ private BottomSheetDialog bottomSheetDialog ;
27+ private View bottomSheetView ;
28+
29+ private MaterialTextView currentVersionTextView ;
30+ private MaterialTextView latestVersionTextView ;
31+ private MaterialTextView descriptionTextView ;
32+ private MaterialButton downloadButton ;
33+ private MaterialButton cancelButton ;
34+ private LinearProgressIndicator progressBar ;
35+ private LottieAnimationView loadingDots ;
36+ private FrameLayout progressBarLayout ;
37+
38+ /**
39+ * Constructor to initialize the Update Checker Bottom Sheet.
40+ *
41+ * @param activity The activity context.
42+ * @param context The application context.
43+ */
44+ public UpdateCheckerBottomSheet (@ NonNull Activity activity , @ NonNull Context context ) {
45+ this .activity = activity ;
46+ this .context = context ;
47+ initializeBottomSheet ();
48+ }
49+
50+ /** Initializes the bottom sheet dialog and its UI components. */
51+ private void initializeBottomSheet () {
52+ bottomSheetDialog = new BottomSheetDialog (activity );
53+ bottomSheetView =
54+ LayoutInflater .from (activity ).inflate (R .layout .bottom_sheet_update_checker , null );
55+ bottomSheetDialog .setContentView (bottomSheetView );
56+
57+ // Initialize UI components
58+ progressBarLayout = bottomSheetView .findViewById (R .id .progressBarLayout );
59+ currentVersionTextView = bottomSheetView .findViewById (R .id .current_version );
60+ latestVersionTextView = bottomSheetView .findViewById (R .id .latest_version );
61+ descriptionTextView = bottomSheetView .findViewById (R .id .body );
62+ downloadButton = bottomSheetView .findViewById (R .id .download_button );
63+ cancelButton = bottomSheetView .findViewById (R .id .cancel_button );
64+ progressBar = bottomSheetView .findViewById (R .id .download_progress );
65+ loadingDots = bottomSheetView .findViewById (R .id .loading_animation );
66+
67+ adjustProgressBarLayout ();
68+ setUpButtonListeners ();
69+ }
70+
71+ /** Adjusts the progress bar layout to maintain height consistency. */
72+ private void adjustProgressBarLayout () {
73+ progressBarLayout .post (
74+ () -> {
75+ int currentHeight = progressBarLayout .getHeight ();
76+ progressBarLayout .setMinimumHeight (currentHeight );
77+ ViewGroup .LayoutParams params = progressBarLayout .getLayoutParams ();
78+ params .height = currentHeight ;
79+ progressBarLayout .setLayoutParams (params );
8180 });
82- }
83-
84- /**
85- * Populates the UI with version information.
86- */
87- private void populateVersionInfo () {
88- String currentVersionText = context .getString (R .string .current ) + " " +
89- context .getString (R .string .version ) + " : " + BuildConfig .VERSION_NAME ;
90- String latestVersionText = context .getString (R .string .latest ) + " " +
91- context .getString (R .string .version ) + " : " + Preferences .getLatestVersionName ();
92-
93- currentVersionTextView .setText (currentVersionText );
94- latestVersionTextView .setText (latestVersionText );
95- }
96-
97- /**
98- * Sets up listeners for the download and cancel buttons.
99- */
100- private void setUpButtonListeners () {
101- downloadButton .setOnClickListener (v -> {
102- HapticUtils .weakVibrate (v );
103- AppUpdater .fetchLatestReleaseAndInstall (activity , progressBar , descriptionTextView , loadingDots , downloadButton );
81+ }
82+
83+ /** Populates the UI with version information. */
84+ private void populateVersionInfo () {
85+ String currentVersionText =
86+ context .getString (R .string .current )
87+ + " "
88+ + context .getString (R .string .version )
89+ + " : "
90+ + BuildConfig .VERSION_NAME ;
91+ String latestVersionText =
92+ context .getString (R .string .latest )
93+ + " "
94+ + context .getString (R .string .version )
95+ + " : "
96+ + Preferences .getLatestVersionName ();
97+
98+ currentVersionTextView .setText (currentVersionText );
99+ latestVersionTextView .setText (latestVersionText );
100+ }
101+
102+ /** Sets up listeners for the download and cancel buttons. */
103+ private void setUpButtonListeners () {
104+ downloadButton .setOnClickListener (
105+ v -> {
106+ HapticUtils .weakVibrate (v );
107+ FeedbackDialogs .githubDownloadWarning (
108+ context , activity , progressBar , descriptionTextView , loadingDots , downloadButton );
104109 });
105110
106- cancelButton .setOnClickListener (v -> {
107- HapticUtils .weakVibrate (v );
108- dismiss ();
111+ cancelButton .setOnClickListener (
112+ v -> {
113+ HapticUtils .weakVibrate (v );
114+ dismiss ();
109115 });
116+ }
117+
118+ /** Displays the update checker bottom sheet. */
119+ public void show () {
120+ populateVersionInfo ();
121+ bottomSheetDialog .show ();
122+ }
123+
124+ /** Dismisses the bottom sheet if it's currently displayed. */
125+ public void dismiss () {
126+ if (bottomSheetDialog != null && bottomSheetDialog .isShowing ()) {
127+ bottomSheetDialog .dismiss ();
110128 }
111-
112- /**
113- * Displays the update checker bottom sheet.
114- */
115- public void show () {
116- populateVersionInfo ();
117- bottomSheetDialog .show ();
118- }
119-
120- /**
121- * Dismisses the bottom sheet if it's currently displayed.
122- */
123- public void dismiss () {
124- if (bottomSheetDialog != null && bottomSheetDialog .isShowing ()) {
125- bottomSheetDialog .dismiss ();
126- }
127- }
128-
129- /**
130- * Checks if the bottom sheet is currently displayed.
131- *
132- * @return True if showing, otherwise false.
133- */
134- public boolean isShowing () {
135- return bottomSheetDialog != null && bottomSheetDialog .isShowing ();
136- }
137- }
129+ }
130+
131+ /**
132+ * Checks if the bottom sheet is currently displayed.
133+ *
134+ * @return True if showing, otherwise false.
135+ */
136+ public boolean isShowing () {
137+ return bottomSheetDialog != null && bottomSheetDialog .isShowing ();
138+ }
139+ }
0 commit comments