Skip to content

Commit

Permalink
Update dependencies, some small changes, fixes upstream TacoTheDank#45
Browse files Browse the repository at this point in the history
  • Loading branch information
unbiaseduser-github committed Oct 24, 2022
1 parent 3250655 commit b85e1b9
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 60 deletions.
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ plugins {
}

android {
compileSdk 32
buildToolsVersion "32.0.0"
compileSdk 33

defaultConfig {
applicationId "taco.scoop"
minSdk 21
targetSdk 32
targetSdk 33
versionCode 34
versionName "2.4.2"
}
Expand Down Expand Up @@ -47,6 +46,7 @@ android {
buildFeatures {
viewBinding true
}
namespace 'taco.scoop'
}

dependencies {
Expand All @@ -61,8 +61,8 @@ dependencies {
// AndroidX
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.fragment:fragment-ktx:1.5.2'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.fragment:fragment-ktx:1.5.3'
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'

Expand All @@ -71,4 +71,5 @@ dependencies {
implementation 'com.afollestad:inquiry:5.0.0'
implementation 'com.afollestad:material-cab:2.0.1'
implementation 'com.github.topjohnwu.libsu:core:5.0.2'
implementation "dev.rikka.rikkax.lifecycle:lifecycle-shared-viewmodel:1.0.1"
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="taco.scoop"
android:installLocation="internalOnly">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Expand Down
40 changes: 40 additions & 0 deletions app/src/main/java/taco/scoop/core/MainViewModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package taco.scoop.core;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.util.ArrayList;
import java.util.List;

import taco.scoop.core.data.crash.Crash;

public class MainViewModel extends ViewModel {
private final MutableLiveData<List<Crash>> crashes = new MutableLiveData<>(new ArrayList<>());
private final MutableLiveData<String> searchTerm = new MutableLiveData<>("");
private Crash combinedCrash;

public LiveData<List<Crash>> getCrashes() {
return crashes;
}

public void setCrashes(List<Crash> crashes) {
this.crashes.setValue(crashes);
}

public void setSearchTerm(String searchTerm) {
this.searchTerm.setValue(searchTerm);
}

public LiveData<String> getSearchTerm() {
return searchTerm;
}

public void setCombinedCrash(Crash combinedCrash) {
this.combinedCrash = combinedCrash;
}

public Crash getCombinedCrash() {
return combinedCrash;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/taco/scoop/core/data/crash/Crash.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Table
public class Crash implements Parcelable {

public static final Creator<Crash> CREATOR = new Creator<Crash>() {
public static final Creator<Crash> CREATOR = new Creator<>() {
@Override
public Crash createFromParcel(Parcel in) {
return new Crash(in);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/taco/scoop/core/data/crash/CrashLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void loadData(MainActivity activity, boolean combineSameStackTrace,
if (listener == null || listener.isFinishing() || listener.isDestroyed())
return;
if (result == null) {
listener.runOnUiThread(() -> listener.onDataLoaded(null));
listener.runOnUiThread(() -> listener.onDataLoaded(new ArrayList<>()));
return;
}
ArrayList<Crash> data = new ArrayList<>(Arrays.asList(result));
Expand Down Expand Up @@ -139,7 +139,7 @@ private ArrayList<Crash> combineStackTraces(List<Crash> crashes) {
}

private void sortApps(final Context context, ArrayList<Crash> crashes) {
Collections.sort(crashes, new Comparator<Crash>() {
Collections.sort(crashes, new Comparator<>() {
private final Collator sC = Collator.getInstance();

@Override
Expand Down
74 changes: 40 additions & 34 deletions app/src/main/java/taco/scoop/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
import com.afollestad.materialcab.attached.AttachedCab
import com.afollestad.materialcab.attached.destroy
import com.afollestad.materialcab.attached.isActive
import com.afollestad.materialcab.createCab
import rikka.lifecycle.sharedViewModels
import taco.scoop.R
import taco.scoop.core.MainViewModel
import taco.scoop.core.data.crash.Crash
import taco.scoop.core.data.crash.CrashLoader
import taco.scoop.core.db.*
Expand All @@ -29,13 +32,12 @@ import taco.scoop.util.initScoopService
import taco.scoop.util.isServiceActive
import taco.scoop.util.updateLocale

class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQueryTextListener,
SearchView.OnCloseListener {
class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQueryTextListener {
private val mLoader = CrashLoader()
private var mCombineApps = false
private var mHasCrash = false
private var mHandler: Handler? = null
private var mAdapter: CrashAdapter? = null
private lateinit var mAdapter: CrashAdapter
private var mNoItemsScreen: View? = null
private var mCab: AttachedCab? = null

Expand All @@ -51,7 +53,7 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
// a different app in the list
return
if (sVisible && sNewCrash != null) {
mAdapter!!.addCrash(sNewCrash)
mAdapter.addCrash(sNewCrash)
updateViewStates(false)
sNewCrash = null
} else {
Expand All @@ -62,6 +64,9 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
}
}
private lateinit var binding: ActivityMainBinding
private val mainViewModel: MainViewModel by sharedViewModels {
ViewModelProvider(this)[MainViewModel::class.java]
}

override fun onCreate(savedInstanceState: Bundle?) {
updateLocale()
Expand All @@ -75,25 +80,33 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
setSupportActionBar(binding.mainToolbar.toolbar)

mAdapter = CrashAdapter(this, this)
mainViewModel.searchTerm.observe(this) { search ->
mAdapter.search(this, search)
}

binding.mainCrashView.adapter = mAdapter
binding.mainCrashView.isGone = true
ToolbarElevationHelper(binding.mainCrashView, binding.mainToolbar.toolbar)

val i = intent
mHasCrash = i.hasExtra(EXTRA_CRASH)
if (mHasCrash) {
val c: Crash? = i.getParcelableExtra(EXTRA_CRASH)
val c: Crash? = mainViewModel.combinedCrash
val crashes = ArrayList<Crash?>()
crashes.add(c)
c?.children?.let(crashes::addAll)
mAdapter!!.setCrashes(crashes)
mAdapter.setCrashes(crashes)
supportActionBar?.title =
CrashLoader.getAppName(this, c?.packageName, true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
} else {
mainViewModel.crashes.observe(this) {
mAdapter.setCrashes(it)
}
}

mCombineApps = PreferenceHelper.combineSameApps
mAdapter!!.setCombineSameApps(!mHasCrash && mCombineApps)
mAdapter.setCombineSameApps(!mHasCrash && mCombineApps)
binding.mainCrashView.setReverseOrder(mHasCrash || !mCombineApps)

createDatabaseInstance(this, "main")
Expand All @@ -106,23 +119,17 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
updateViewStates(false)
}
} else {
mAdapter!!.restoreInstanceState(savedInstanceState)
updateViewStates(false)
}
mHandler = Handler(Looper.getMainLooper())

checkAvailability()
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mAdapter!!.saveInstanceState(outState)
}

override fun onResume() {
super.onResume()
// Cheap way to instantly apply changes
mAdapter!!.setSearchPackageName(
mAdapter.setSearchPackageName(
this, PreferenceHelper.searchPackageName
)
sVisible = true
Expand All @@ -145,7 +152,7 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu

override fun onBackPressed() {
if (mCab.isActive()) {
mAdapter!!.setSelectionEnabled(false)
mAdapter.setSelectionEnabled(false)
} else {
super.onBackPressed()
}
Expand All @@ -160,7 +167,7 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
if (mCheckPending) {
newLoading = true
}
val empty = mAdapter!!.isEmpty
val empty = mAdapter.isEmpty
binding.mainProgressbar.isVisible = newLoading
binding.mainCrashView.isGone = newLoading || empty || !mIsAvailable

Expand All @@ -180,7 +187,7 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
}

private fun loadData() {
mAdapter!!.setSelectionEnabled(false)
mAdapter.setSelectionEnabled(false)
updateViewStates(true)
mLoader.loadData(
this,
Expand All @@ -190,8 +197,8 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
)
}

fun onDataLoaded(data: ArrayList<Crash?>?) {
mAdapter!!.setCrashes(data)
fun onDataLoaded(data: List<Crash?>) {
mainViewModel.setCrashes(data)
updateViewStates(false)
}

Expand All @@ -211,9 +218,10 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu

override fun onCrashClicked(crash: Crash) {
if (mCombineApps && !mHasCrash) {
mainViewModel.combinedCrash = crash
activityResultLauncher.launch(
Intent(this, MainActivity::class.java)
.putExtra(EXTRA_CRASH, crash)
.putExtra(EXTRA_CRASH, true)
)
} else {
startActivity(
Expand Down Expand Up @@ -252,14 +260,14 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
true
}
onDestroy {
mAdapter!!.setSelectionEnabled(false)
mAdapter.setSelectionEnabled(false)
true
}
}
}

private fun showDeletePrompt() {
val items = mAdapter!!.selectedItems
val items = mAdapter.selectedItems
if (items.isEmpty()) {
return
}
Expand All @@ -272,9 +280,9 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok) { _, _ ->
deleteItems(items)
mAdapter!!.setSelectionEnabled(false)
mAdapter.setSelectionEnabled(false)
setResult(RESULT_OK) // Reload overview when going back to reflect changes
if (mHasCrash && mAdapter!!.isEmpty) {
if (mHasCrash && mAdapter.isEmpty) {
finish() // Everything deleted, go back to overview
} else {
updateViewStates(false)
Expand All @@ -291,15 +299,15 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
cc.hiddenIds?.let {
deleteWhereIn(*it.toTypedArray())
}
mAdapter!!.removeCrash(cc)
mAdapter.removeCrash(cc)
}
deleteValues(c.children)
}
c.hiddenIds?.let {
deleteWhereIn(*it.toTypedArray())
}
deleteValues(listOf(c))
mAdapter!!.removeCrash(c)
mAdapter.removeCrash(c)
}
}

Expand All @@ -308,17 +316,15 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
val searchItem = menu.findItem(R.id.menu_main_search)
val searchView = searchItem.actionView as SearchView
searchView.setOnQueryTextListener(this)
searchView.setOnCloseListener(this)
if ((mainViewModel.searchTerm.value as String).isNotEmpty()) {
searchItem.expandActionView()
searchView.setQuery(mainViewModel.searchTerm.value, false)
}
return true
}

override fun onClose(): Boolean {
mAdapter!!.search(this, null)
return false
}

override fun onQueryTextChange(newText: String): Boolean {
mAdapter!!.search(this, newText)
mainViewModel.setSearchTerm(newText)
return true
}

Expand All @@ -334,7 +340,7 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok) { _, _ ->
dropTable()
onDataLoaded(null)
onDataLoaded(ArrayList())
}
.show()
return true
Expand Down
Loading

0 comments on commit b85e1b9

Please sign in to comment.