Skip to content

Commit 7182b2f

Browse files
optimize ui
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 7403a28 commit 7182b2f

12 files changed

Lines changed: 267 additions & 54 deletions

File tree

app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.animation.Animator
88
import android.animation.AnimatorListenerAdapter
99
import android.annotation.SuppressLint
1010
import android.content.Context
11+
import android.content.DialogInterface
1112
import android.content.Intent
1213
import android.content.res.Configuration
1314
import android.graphics.Color
@@ -57,6 +58,8 @@ import com.fox2code.mmm.utils.io.net.Http.Companion.cleanDnsCache
5758
import com.fox2code.mmm.utils.io.net.Http.Companion.hasWebView
5859
import com.fox2code.mmm.utils.room.ReposListDatabase
5960
import com.google.android.material.bottomnavigation.BottomNavigationView
61+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
62+
import com.google.android.material.floatingactionbutton.FloatingActionButton
6063
import com.google.android.material.progressindicator.LinearProgressIndicator
6164
import org.matomo.sdk.extra.TrackHelper
6265
import 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)

app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyRepoData.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,18 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
9898
editor.remove("pref_androidacy_api_token")
9999
editor.apply()
100100
return false
101+
} else {
102+
val handler = Handler(Looper.getMainLooper())
103+
handler.post {
104+
Toast.makeText(
105+
INSTANCE,
106+
INSTANCE!!.getString(R.string.androidacy_api_error, e.errorCode),
107+
Toast.LENGTH_LONG
108+
).show()
109+
}
101110
}
102-
throw e
111+
Timber.w(e)
112+
false
103113
} catch (e: JSONException) {
104114
// response is not JSON
105115
Timber.w("Invalid token, resetting...")

app/src/main/kotlin/com/fox2code/mmm/installer/InstallerActivity.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.fox2code.mmm.androidacy.AndroidacyUtil
3838
import com.fox2code.mmm.module.ActionButtonType
3939
import com.fox2code.mmm.utils.FastException
4040
import com.fox2code.mmm.utils.IntentHelper
41+
import com.fox2code.mmm.utils.RuntimeUtils
4142
import com.fox2code.mmm.utils.io.Files.Companion.copy
4243
import com.fox2code.mmm.utils.io.Files.Companion.fixJavaZipHax
4344
import com.fox2code.mmm.utils.io.Files.Companion.fixSourceArchiveShit
@@ -636,24 +637,25 @@ class InstallerActivity : FoxActivity() {
636637
}
637638
setDisplayHomeAsUpEnabled(true)
638639
progressIndicator!!.visibility = View.GONE
639-
640-
// This should be improved ?
641-
val rbtCmd =
642-
"/system/bin/svc power reboot || /system/bin/reboot || setprop sys.powerctl reboot"
643640
rebootFloatingButton!!.setOnClickListener { _: View? ->
644-
if (warnReboot || MainApplication.shouldPreventReboot()) {
641+
if (MainApplication.shouldPreventReboot()) {
642+
// toast and do nothing
643+
Toast.makeText(
644+
this,
645+
R.string.install_terminal_reboot_prevented,
646+
Toast.LENGTH_SHORT
647+
).show()
648+
} else {
645649
val builder = MaterialAlertDialogBuilder(this)
646650
builder.setTitle(R.string.install_terminal_reboot_now)
647651
.setMessage(R.string.install_terminal_reboot_now_message)
648652
.setCancelable(false).setIcon(
649653
R.drawable.ic_reboot_24
650654
).setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int ->
651-
Shell.cmd(rbtCmd).submit()
655+
RuntimeUtils.reboot(this, RuntimeUtils.RebootMode.REBOOT)
652656
}
653657
.setNegativeButton(R.string.no) { x: DialogInterface, _: Int -> x.dismiss() }
654658
.show()
655-
} else {
656-
Shell.cmd(rbtCmd).submit()
657659
}
658660
}
659661
rebootFloatingButton!!.isEnabled = true

app/src/main/kotlin/com/fox2code/mmm/manager/ModuleManager.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import java.io.InputStreamReader
2727
import java.nio.charset.StandardCharsets
2828

2929
class ModuleManager private constructor() : SyncManager() {
30-
private val moduleInfos: HashMap<String, LocalModuleInfo> = HashMap()
30+
private var moduleInfos: HashMap<String, LocalModuleInfo> = HashMap()
3131
private val bootPrefs: SharedPreferences = MainApplication.bootSharedPreferences!!
3232
private var updatableModuleCount = 0
3333

@@ -200,12 +200,15 @@ class ModuleManager private constructor() : SyncManager() {
200200
}
201201
}
202202

203-
val modules: HashMap<String, LocalModuleInfo>
203+
var modules: HashMap<String, LocalModuleInfo> = HashMap()
204204
get() {
205205
afterScan()
206206
return moduleInfos
207207
}
208-
208+
set(value) {
209+
moduleInfos = value
210+
field = value
211+
}
209212
@Suppress("unused")
210213
fun getUpdatableModuleCount(): Int {
211214
afterScan()

app/src/main/kotlin/com/fox2code/mmm/module/ModuleHolder.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ModuleHolder : Comparable<ModuleHolder?> {
4343

4444
constructor(notificationType: NotificationType) {
4545
moduleId = ""
46-
this.notificationType = Objects.requireNonNull(notificationType)
46+
this.notificationType = notificationType
4747
separator = null
4848
footerPx = -1
4949
}
@@ -106,17 +106,16 @@ class ModuleHolder : Comparable<ModuleHolder?> {
106106

107107
val type: Type
108108
get() = if (footerPx != -1) {
109-
Timber.i("Module %s is footer", moduleId)
110109
Type.FOOTER
111110
} else if (separator != null) {
112-
Timber.i("Module %s is separator", moduleId)
113111
Type.SEPARATOR
114112
} else if (notificationType != null) {
115-
Timber.i("Module %s is notification", moduleId)
116113
Type.NOTIFICATION
117114
} else if (moduleInfo == null) {
115+
Timber.i("Module %s is null and probably is a remote module", moduleId)
118116
Type.INSTALLABLE
119117
} else if (moduleInfo!!.versionCode < moduleInfo!!.updateVersionCode || repoModule != null && moduleInfo!!.versionCode < repoModule!!.moduleInfo.versionCode) {
118+
Timber.i("Module %s is updateable", moduleId)
120119
var ignoreUpdate = false
121120
try {
122121
if (getSharedPreferences("mmm")?.getStringSet("pref_background_update_check_excludes", HashSet())!!
@@ -195,6 +194,7 @@ class ModuleHolder : Comparable<ModuleHolder?> {
195194
Type.UPDATABLE
196195
}
197196
} else {
197+
Timber.i("Module %s is installed", moduleId)
198198
Type.INSTALLED
199199
}
200200

app/src/main/kotlin/com/fox2code/mmm/utils/RuntimeUtils.kt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ import com.fox2code.mmm.R
2828
import com.fox2code.mmm.SetupActivity
2929
import com.google.android.material.dialog.MaterialAlertDialogBuilder
3030
import com.google.android.material.snackbar.Snackbar
31+
import com.topjohnwu.superuser.Shell
3132
import timber.log.Timber
3233

3334
@Suppress("UNUSED_PARAMETER")
3435
class RuntimeUtils {
36+
enum class RebootMode {
37+
REBOOT, RECOVERY, BOOTLOADER, EDL
38+
}
39+
3540
@SuppressLint("RestrictedApi")
3641
private fun ensurePermissions(context: Context, activity: MainActivity) {
3742
if (BuildConfig.DEBUG) Timber.i("Ensure Permissions")
@@ -269,4 +274,46 @@ class RuntimeUtils {
269274
prefs.edit().putLong("ugsns4", System.currentTimeMillis()).apply()
270275
Timber.i("showUpgradeSnackbar done")
271276
}
277+
278+
companion object {
279+
fun reboot(mainActivity: FoxActivity, reboot: RebootMode) {
280+
// reboot based on the reboot cmd from the enum we were passed
281+
when (reboot) {
282+
RebootMode.REBOOT -> {
283+
showRebootDialog(mainActivity) {
284+
Shell.cmd("/system/bin/svc power reboot || /system/bin/reboot").submit()
285+
}
286+
}
287+
RebootMode.RECOVERY -> {
288+
// KEYCODE_POWER = 26, hide incorrect "Factory data reset" message
289+
showRebootDialog(mainActivity) {
290+
Shell.cmd("/system/bin/input keyevent 26").submit()
291+
}
292+
}
293+
RebootMode.BOOTLOADER -> {
294+
showRebootDialog(mainActivity) {
295+
Shell.cmd("/system/bin/svc power reboot bootloader || /system/bin/reboot bootloader")
296+
.submit()
297+
}
298+
}
299+
RebootMode.EDL -> {
300+
showRebootDialog(mainActivity) {
301+
Shell.cmd("/system/bin/reboot edl").submit()
302+
}
303+
}
304+
}
305+
}
306+
307+
private fun showRebootDialog(mainActivity: FoxActivity, function: () -> Unit) {
308+
val dialog = MaterialAlertDialogBuilder(mainActivity)
309+
.setTitle(R.string.reboot)
310+
.setMessage(R.string.install_terminal_reboot_now_message)
311+
.setPositiveButton(R.string.reboot) { _, _ ->
312+
function()
313+
}
314+
.setNegativeButton(R.string.cancel) { _, _ -> }
315+
.create()
316+
dialog.show()
317+
}
318+
}
272319
}

0 commit comments

Comments
 (0)