@@ -8,6 +8,7 @@ import android.animation.Animator
88import android.animation.AnimatorListenerAdapter
99import android.annotation.SuppressLint
1010import android.content.Context
11+ import android.content.DialogInterface
1112import android.content.Intent
1213import android.content.res.Configuration
1314import android.graphics.Color
@@ -57,6 +58,8 @@ import com.fox2code.mmm.utils.io.net.Http.Companion.cleanDnsCache
5758import com.fox2code.mmm.utils.io.net.Http.Companion.hasWebView
5859import com.fox2code.mmm.utils.room.ReposListDatabase
5960import com.google.android.material.bottomnavigation.BottomNavigationView
61+ import com.google.android.material.dialog.MaterialAlertDialogBuilder
62+ import com.google.android.material.floatingactionbutton.FloatingActionButton
6063import com.google.android.material.progressindicator.LinearProgressIndicator
6164import org.matomo.sdk.extra.TrackHelper
6265import timber.log.Timber
@@ -81,6 +84,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
8184 private var moduleListOnline: RecyclerView ? = null
8285 private var searchCard: CardView ? = null
8386 private var searchView: SearchView ? = null
87+ private var rebootFab: FloatingActionButton ? = null
8488 private var initMode = false
8589 private var runtimeUtils: RuntimeUtils ? = null
8690
@@ -113,9 +117,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
113117 // track enabled repos
114118 Thread {
115119 val db = Room .databaseBuilder(
116- applicationContext,
117- ReposListDatabase ::class .java,
118- " ReposList.db"
120+ applicationContext, ReposListDatabase ::class .java, " ReposList.db"
119121 ).build()
120122 val repoDao = db.reposListDao()
121123 val repos = repoDao.getAll()
@@ -175,6 +177,11 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
175177 searchView = findViewById(R .id.search_bar)
176178 val searchView = searchView!!
177179 searchView.isIconified = true
180+ // when the search view is collapsed or user hits x, hide the search view
181+ searchView.setOnCloseListener {
182+ searchView.visibility = View .GONE
183+ false
184+ }
178185 moduleViewAdapter = ModuleViewAdapter ()
179186 moduleViewAdapterOnline = ModuleViewAdapter ()
180187 val moduleList = moduleList!!
@@ -190,14 +197,47 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
190197 updateBlurState()
191198 // hideActionBar();
192199 runtimeUtils!! .checkShowInitialSetup(this , this )
200+ rebootFab = findViewById(R .id.reboot_fab)
201+ val rebootFab = rebootFab!!
202+
203+ // set on click listener for reboot fab
204+ rebootFab.setOnClickListener {
205+ // show reboot dialog with options to reboot, reboot to recovery, bootloader, or edl, and use RuntimeUtils to reboot
206+ val rebootDialog = MaterialAlertDialogBuilder (this @MainActivity)
207+ .setTitle(R .string.reboot)
208+ .setItems(
209+ arrayOf(
210+ getString(R .string.reboot),
211+ getString(R .string.reboot_recovery),
212+ getString(R .string.reboot_bootloader),
213+ getString(R .string.reboot_edl)
214+ )
215+ ) { _: DialogInterface ? , which: Int ->
216+ when (which) {
217+ 0 -> RuntimeUtils .reboot(this @MainActivity, RuntimeUtils .RebootMode .REBOOT )
218+ 1 -> RuntimeUtils .reboot(this @MainActivity, RuntimeUtils .RebootMode .RECOVERY )
219+ 2 -> RuntimeUtils .reboot(this @MainActivity, RuntimeUtils .RebootMode .BOOTLOADER )
220+ 3 -> RuntimeUtils .reboot(this @MainActivity, RuntimeUtils .RebootMode .EDL )
221+ }
222+ }
223+ .setNegativeButton(R .string.cancel, null )
224+ .create()
225+ rebootDialog.show()
226+ }
193227 val searchCard = searchCard!!
228+ // copy reboot fab style to search card
229+ searchCard.elevation = rebootFab.elevation
230+ searchCard.translationY = rebootFab.translationY
231+ searchCard.foreground = rebootFab.foreground
194232 moduleList.addOnScrollListener(object : RecyclerView .OnScrollListener () {
195233 override fun onScrollStateChanged (recyclerView : RecyclerView , newState : Int ) {
196234 if (newState != RecyclerView .SCROLL_STATE_IDLE ) searchView.clearFocus()
197- // hide search view when scrolling
235+ // hide search view and reboot fab when scrolling
198236 if (newState == RecyclerView .SCROLL_STATE_DRAGGING ) {
199237 searchCard.animate().translationY(- searchCard.height.toFloat())
200238 .setInterpolator(AccelerateInterpolator (2f )).start()
239+ rebootFab.animate().translationY(rebootFab.height.toFloat())
240+ .setInterpolator(AccelerateInterpolator (2f )).start()
201241 }
202242 }
203243
@@ -207,6 +247,8 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
207247 if (dy < 0 ) {
208248 searchCard.animate().translationY(0f )
209249 .setInterpolator(DecelerateInterpolator (2f )).start()
250+ rebootFab.animate().translationY(0f ).setInterpolator(DecelerateInterpolator (2f ))
251+ .start()
210252 }
211253 }
212254 })
@@ -218,6 +260,8 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
218260 if (newState == RecyclerView .SCROLL_STATE_DRAGGING ) {
219261 searchCard.animate().translationY(- searchCard.height.toFloat())
220262 .setInterpolator(AccelerateInterpolator (2f )).start()
263+ rebootFab.animate().translationY(rebootFab.height.toFloat())
264+ .setInterpolator(AccelerateInterpolator (2f )).start()
221265 }
222266 }
223267
@@ -227,10 +271,10 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
227271 if (dy < 0 ) {
228272 searchCard.animate().translationY(0f )
229273 .setInterpolator(DecelerateInterpolator (2f )).start()
274+ rebootFab.animate().translationY(0f )
230275 }
231276 }
232277 })
233- searchCard.radius = searchCard.height / 2f
234278 searchView.minimumHeight = FoxDisplay .dpToPixel(16f )
235279 searchView.imeOptions = EditorInfo .IME_ACTION_SEARCH or EditorInfo .IME_FLAG_NO_FULLSCREEN
236280 searchView.setOnQueryTextListener(this )
@@ -390,19 +434,20 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
390434 if (BuildConfig .DEBUG ) Timber .i(" Check Update" )
391435 // update repos
392436 if (hasWebView()) {
393- val updateListener: SyncManager .UpdateListener = object : SyncManager .UpdateListener {
394- override fun update (value : Double ) {
395- runOnUiThread(if (max == 0 ) Runnable {
396- progressIndicator.setProgressCompat(
397- (value * PRECISION ).toInt(), true
398- )
399- } else Runnable {
400- progressIndicator.setProgressCompat(
401- (value * PRECISION * 0.75f ).toInt(), true
402- )
403- })
437+ val updateListener: SyncManager .UpdateListener =
438+ object : SyncManager .UpdateListener {
439+ override fun update (value : Double ) {
440+ runOnUiThread(if (max == 0 ) Runnable {
441+ progressIndicator.setProgressCompat(
442+ (value * PRECISION ).toInt(), true
443+ )
444+ } else Runnable {
445+ progressIndicator.setProgressCompat(
446+ (value * PRECISION * 0.75f ).toInt(), true
447+ )
448+ })
449+ }
404450 }
405- }
406451 RepoManager .getINSTANCE()!! .update(updateListener)
407452 }
408453 // various notifications
@@ -525,7 +570,6 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
525570 moduleViewListBuilderOnline.setHeaderPx(statusBarHeight)
526571 moduleViewListBuilder.setFooterPx(FoxDisplay .dpToPixel(4f ) + bottomInset + searchCard!! .height)
527572 moduleViewListBuilderOnline.setFooterPx(FoxDisplay .dpToPixel(4f ) + bottomInset + searchCard!! .height)
528- searchCard!! .radius = searchCard!! .height / 2f
529573 moduleViewListBuilder.updateInsets()
530574 // this.actionBarBlur.invalidate();
531575 overScrollInsetTop = statusBarHeight
@@ -611,15 +655,16 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
611655 progressIndicator!! .max = PRECISION
612656 }
613657 if (BuildConfig .DEBUG ) Timber .i(" Check Update" )
614- val updateListener: SyncManager .UpdateListener = object : SyncManager .UpdateListener {
615- override fun update (value : Double ) {
616- runOnUiThread {
617- progressIndicator!! .setProgressCompat(
618- (value * PRECISION ).toInt(), true
619- )
658+ val updateListener: SyncManager .UpdateListener =
659+ object : SyncManager .UpdateListener {
660+ override fun update (value : Double ) {
661+ runOnUiThread {
662+ progressIndicator!! .setProgressCompat(
663+ (value * PRECISION ).toInt(), true
664+ )
665+ }
620666 }
621667 }
622- }
623668 RepoManager .getINSTANCE()!! .update(updateListener)
624669 runOnUiThread {
625670 progressIndicator!! .setProgressCompat(PRECISION , true )
0 commit comments