fix updater and hook up online repo tab

fixes #223 but there's a couple outstanding bugs related to the tabs that will be fixed later

fixed lack of bg on chips in black theme

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/284/head
androidacy-user 1 year ago
parent 704771d5e2
commit c80833b2c0

@ -16,6 +16,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
@ -63,9 +64,11 @@ import timber.log.Timber;
public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRefreshListener, SearchView.OnQueryTextListener, SearchView.OnCloseListener, OverScrollManager.OverScrollHelper { public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRefreshListener, SearchView.OnQueryTextListener, SearchView.OnCloseListener, OverScrollManager.OverScrollHelper {
private static final int PRECISION = 10000; private static final int PRECISION = 10000;
public static boolean doSetupNowRunning = true; public static boolean doSetupNowRunning = true;
public static boolean doSetupRestarting = false;
public final ModuleViewListBuilder moduleViewListBuilder; public final ModuleViewListBuilder moduleViewListBuilder;
public LinearProgressIndicator progressIndicator; public LinearProgressIndicator progressIndicator;
private ModuleViewAdapter moduleViewAdapter; private ModuleViewAdapter moduleViewAdapter;
private ModuleViewAdapter moduleViewAdapterOnline;
private SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
private int swipeRefreshLayoutOrigStartOffset; private int swipeRefreshLayoutOrigStartOffset;
private int swipeRefreshLayoutOrigEndOffset; private int swipeRefreshLayoutOrigEndOffset;
@ -80,7 +83,6 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
private CardView searchCard; private CardView searchCard;
private SearchView searchView; private SearchView searchView;
private boolean initMode; private boolean initMode;
public static boolean doSetupRestarting = false;
private boolean urlFactoryInstalled = false; private boolean urlFactoryInstalled = false;
public MainActivity() { public MainActivity() {
@ -127,18 +129,6 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
Toast.makeText(this, R.string.not_official_build, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.not_official_build, Toast.LENGTH_LONG).show();
} }
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
// on the bottom nav, there's a settings item. open the settings activity when it's clicked.
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnItemSelectedListener(item -> {
if (item.getItemId() == R.id.settings_menu_item) {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
}
return true;
});
// set the selected item to the installed tab
bottomNavigationView.setSelectedItemId(R.id.installed_menu_item);
// set the bottom padding of the main layout to the height of the bottom nav
findViewById(R.id.root_container).setPadding(0, 0, 0, bottomNavigationView.getHeight());
this.setTitle(R.string.app_name); this.setTitle(R.string.app_name);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, 0); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, 0);
setActionBarBackground(null); setActionBarBackground(null);
@ -161,8 +151,11 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.searchCard = findViewById(R.id.search_card); this.searchCard = findViewById(R.id.search_card);
this.searchView = findViewById(R.id.search_bar); this.searchView = findViewById(R.id.search_bar);
this.moduleViewAdapter = new ModuleViewAdapter(); this.moduleViewAdapter = new ModuleViewAdapter();
this.moduleViewAdapterOnline = new ModuleViewAdapter();
this.moduleList.setAdapter(this.moduleViewAdapter); this.moduleList.setAdapter(this.moduleViewAdapter);
this.moduleListOnline.setAdapter(this.moduleViewAdapterOnline);
this.moduleList.setLayoutManager(new LinearLayoutManager(this)); this.moduleList.setLayoutManager(new LinearLayoutManager(this));
this.moduleListOnline.setLayoutManager(new LinearLayoutManager(this));
this.moduleList.setItemViewCacheSize(4); // Default is 2 this.moduleList.setItemViewCacheSize(4); // Default is 2
this.swipeRefreshLayout.setOnRefreshListener(this); this.swipeRefreshLayout.setOnRefreshListener(this);
this.actionBarBlur.setBackground(this.actionBarBackground); this.actionBarBlur.setBackground(this.actionBarBackground);
@ -195,6 +188,27 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
this.cardIconifyUpdate(); this.cardIconifyUpdate();
this.updateScreenInsets(this.getResources().getConfiguration()); this.updateScreenInsets(this.getResources().getConfiguration());
// on the bottom nav, there's a settings item. open the settings activity when it's clicked.
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
// set the bottom padding of the main layout to the height of the bottom nav
findViewById(R.id.root_container).setPadding(0, 0, 0, bottomNavigationView.getHeight());
bottomNavigationView.setSelectedItemId(R.id.installed_menu_item);
MenuItem installedMenuItem = bottomNavigationView.getMenu().findItem(R.id.installed_menu_item);
installedMenuItem.setChecked(true);
bottomNavigationView.setOnItemSelectedListener(item -> {
if (item.getItemId() == R.id.settings_menu_item) {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
} else if (item.getItemId() == R.id.online_menu_item) {
// set module_list_online as visible and module_list as gone
this.moduleList.setVisibility(View.GONE);
this.moduleListOnline.setVisibility(View.VISIBLE);
} else if (item.getItemId() == R.id.installed_menu_item) {
// set module_list_online as gone and module_list as visible
this.moduleList.setVisibility(View.VISIBLE);
this.moduleListOnline.setVisibility(View.GONE);
}
return true;
});
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() { InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
@Override @Override
public void onPathReceived(String path) { public void onPathReceived(String path) {
@ -244,19 +258,23 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// Log all preferences changes // Log all preferences changes
MainApplication.getSharedPreferences().registerOnSharedPreferenceChangeListener((prefs, key) -> Timber.i("onSharedPreferenceChanged: " + key + " = " + prefs.getAll().get(key))); MainApplication.getSharedPreferences().registerOnSharedPreferenceChangeListener((prefs, key) -> Timber.i("onSharedPreferenceChanged: " + key + " = " + prefs.getAll().get(key)));
} }
Timber.i("Scanning for modules!"); Timber.i("Scanning for modules!");
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Timber.i("Initialize Update"); Timber.i("Initialize Update");
final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount(); final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount();
if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) { if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) {
Timber.w("Need update on create?"); Timber.w("Need update on create");
} }
// update compat metadata
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Timber.i("Check Update Compat"); Timber.i("Check Update Compat");
AppUpdateManager.getAppUpdateManager().checkUpdateCompat(); AppUpdateManager.getAppUpdateManager().checkUpdateCompat();
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Timber.i("Check Update"); Timber.i("Check Update");
// update repos
RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () -> progressIndicator.setProgressCompat((int) (value * PRECISION), true) : () -> progressIndicator.setProgressCompat((int) (value * PRECISION * 0.75F), true))); RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () -> progressIndicator.setProgressCompat((int) (value * PRECISION), true) : () -> progressIndicator.setProgressCompat((int) (value * PRECISION * 0.75F), true)));
// various notifications
NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilder); NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilder);
// Add debug notification for debug builds // Add debug notification for debug builds
if (!NotificationType.DEBUG.shouldRemove()) { if (!NotificationType.DEBUG.shouldRemove()) {
@ -278,7 +296,6 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
if (max != 0) { if (max != 0) {
int current = 0; int current = 0;
// noodleDebug.push("");
for (LocalModuleInfo localModuleInfo : ModuleManager.getINSTANCE().getModules().values()) { for (LocalModuleInfo localModuleInfo : ModuleManager.getINSTANCE().getModules().values()) {
if (localModuleInfo.updateJson != null) { if (localModuleInfo.updateJson != null) {
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
@ -307,9 +324,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
Timber.i("Apply"); Timber.i("Apply");
RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilder::appendRemoteModules); RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilder::appendRemoteModules);
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter); moduleViewListBuilder.applyTo(moduleListOnline, moduleViewAdapterOnline);
Timber.i("Finished app opening state!"); Timber.i("Finished app opening state!");
// noodleDebug.unbind();
} }
}, true); }, true);
ExternalHelper.INSTANCE.refreshHelper(this); ExternalHelper.INSTANCE.refreshHelper(this);
@ -441,7 +457,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
Timber.i("Apply"); Timber.i("Apply");
RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilder::appendRemoteModules); RepoManager.getINSTANCE().runAfterUpdate(moduleViewListBuilder::appendRemoteModules);
Timber.i("Common Before applyTo"); Timber.i("Common Before applyTo");
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter); moduleViewListBuilder.applyTo(moduleListOnline, moduleViewAdapterOnline);
Timber.i("Common After"); Timber.i("Common After");
} }
}); });
@ -467,7 +483,6 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
// this.swipeRefreshLayout.setRefreshing(true); ?? // this.swipeRefreshLayout.setRefreshing(true); ??
new Thread(() -> { new Thread(() -> {
Http.cleanDnsCache(); // Allow DNS reload from network Http.cleanDnsCache(); // Allow DNS reload from network
// noodleDebug.push("Check Update");
final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount(); final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount();
RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () -> progressIndicator.setProgressCompat((int) (value * PRECISION), true) : () -> progressIndicator.setProgressCompat((int) (value * PRECISION * 0.75F), true))); RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () -> progressIndicator.setProgressCompat((int) (value * PRECISION), true) : () -> progressIndicator.setProgressCompat((int) (value * PRECISION * 0.75F), true)));
NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilder); NotificationType.NEED_CAPTCHA_ANDROIDACY.autoAdd(moduleViewListBuilder);
@ -608,7 +623,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
// Log if granted via onRequestPermissionsResult // Log if granted via onRequestPermissionsResult
boolean granted = ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED; boolean granted = ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED;
Timber.i( "Request Notification Permission Done. Result: %s", granted); Timber.i("Request Notification Permission Done. Result: %s", granted);
} }
doSetupNowRunning = false; doSetupNowRunning = false;
} }

@ -160,38 +160,46 @@ public class UpdateActivity extends FoxActivity {
} }
public void checkForUpdate() { public void checkForUpdate() {
LinearProgressIndicator progressIndicator = findViewById(R.id.update_progress);
progressIndicator.setIndeterminate(true);
// get status text view // get status text view
MaterialTextView statusTextView = findViewById(R.id.update_progress_text); MaterialTextView statusTextView = findViewById(R.id.update_progress_text);
// set status text to checking for update LinearProgressIndicator progressIndicator = findViewById(R.id.update_progress);
statusTextView.setText(R.string.checking_for_update); runOnUiThread(() -> {
// set progress bar to indeterminate progressIndicator.setIndeterminate(true);
progressIndicator.setIndeterminate(true); // set status text to checking for update
statusTextView.setText(R.string.checking_for_update);
// set progress bar to indeterminate
progressIndicator.setIndeterminate(true);
});
// check for update // check for update
boolean shouldUpdate = AppUpdateManager.getAppUpdateManager().peekShouldUpdate(); boolean shouldUpdate = AppUpdateManager.getAppUpdateManager().peekShouldUpdate();
// if shouldUpdate is true, then we have an update // if shouldUpdate is true, then we have an update
if (shouldUpdate) { if (shouldUpdate) {
// set status text to update available runOnUiThread(() -> {
statusTextView.setText(R.string.update_available); // set status text to update available
// set button text to download statusTextView.setText(R.string.update_available);
MaterialButton button = findViewById(R.id.update_button); // set button text to download
button.setText(R.string.download_update); MaterialButton button = findViewById(R.id.update_button);
button.setText(R.string.download_update);
});
// return // return
} else { } else {
// set status text to no update available runOnUiThread(() -> {
statusTextView.setText(R.string.no_update_available); // set status text to no update available
statusTextView.setText(R.string.no_update_available);
});
// set progress bar to error // set progress bar to error
// return // return
} }
progressIndicator.setIndeterminate(false); runOnUiThread(() -> {
progressIndicator.setProgressCompat(100, false); progressIndicator.setIndeterminate(false);
progressIndicator.setProgressCompat(100, false);
});
return; return;
} }
public void downloadUpdate() throws JSONException { public void downloadUpdate() throws JSONException {
LinearProgressIndicator progressIndicator = findViewById(R.id.update_progress); LinearProgressIndicator progressIndicator = findViewById(R.id.update_progress);
progressIndicator.setIndeterminate(true); runOnUiThread(() -> progressIndicator.setIndeterminate(true));
// get status text view // get status text view
MaterialTextView statusTextView = findViewById(R.id.update_progress_text); MaterialTextView statusTextView = findViewById(R.id.update_progress_text);
byte[] lastestJSON = new byte[0]; byte[] lastestJSON = new byte[0];
@ -201,9 +209,11 @@ public class UpdateActivity extends FoxActivity {
Exception e) { Exception e) {
// when logging, REMOVE the json from the log // when logging, REMOVE the json from the log
Timber.e(e, "Error downloading update info"); Timber.e(e, "Error downloading update info");
progressIndicator.setIndeterminate(false); runOnUiThread(() -> {
progressIndicator.setProgressCompat(100, false); progressIndicator.setIndeterminate(false);
statusTextView.setText(R.string.error_download_update); progressIndicator.setProgressCompat(100, false);
statusTextView.setText(R.string.error_download_update);
});
} }
// convert to JSON // convert to JSON
JSONObject latestJSON = new JSONObject(new String(lastestJSON)); JSONObject latestJSON = new JSONObject(new String(lastestJSON));
@ -229,10 +239,12 @@ public class UpdateActivity extends FoxActivity {
// if asset is null, then we are in a bad state // if asset is null, then we are in a bad state
if (Objects.isNull(asset)) { if (Objects.isNull(asset)) {
// set status text to error // set status text to error
statusTextView.setText(R.string.error_no_asset); runOnUiThread(() -> {
// set progress bar to error statusTextView.setText(R.string.error_no_asset);
progressIndicator.setIndeterminate(false); // set progress bar to error
progressIndicator.setProgressCompat(100, false); progressIndicator.setIndeterminate(false);
progressIndicator.setProgressCompat(100, false);
});
// return // return
return; return;
} }

@ -7,6 +7,7 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.fox2code.mmm.AppUpdateManager; import com.fox2code.mmm.AppUpdateManager;
import com.fox2code.mmm.BuildConfig;
import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.NotificationType; import com.fox2code.mmm.NotificationType;
import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.installer.InstallerInitializer;
@ -93,6 +94,9 @@ public class ModuleViewListBuilder {
} }
public void appendRemoteModules() { public void appendRemoteModules() {
if (BuildConfig.DEBUG) {
Timber.i("appendRemoteModules() called");
}
synchronized (this.updateLock) { synchronized (this.updateLock) {
boolean showIncompatible = MainApplication.isShowIncompatibleModules(); boolean showIncompatible = MainApplication.isShowIncompatibleModules();
for (ModuleHolder moduleHolder : this.mappedModuleHolders.values()) { for (ModuleHolder moduleHolder : this.mappedModuleHolders.values()) {

@ -36,10 +36,8 @@
<!-- Override chip style --> <!-- Override chip style -->
<item name="chipBackgroundColor">@color/system_accent2_700</item> <item name="chipBackgroundColor">@color/system_accent2_700</item>
<item name="chipSurfaceColor">@color/system_accent2_700</item> <item name="chipSurfaceColor">@color/system_accent2_700</item>
<!-- <item name="colorOnPrimary">@color/system_accent2_100</item> <!-- chips should be dark, not black -->
<item name="colorOnSecondary">@color/system_accent2_100</item> <item name="chipStyle">@style/Widget.Material.Chip.Choice.Dark</item>
<item name="colorOnBackground">@color/system_accent2_100</item>
<item name="colorOnSurface">@color/system_accent2_100</item> -->
</style> </style>
<style name="Widget.Material3.Chip.Choice.Dark" parent="Widget.Material3.Chip.Assist"> <style name="Widget.Material3.Chip.Choice.Dark" parent="Widget.Material3.Chip.Assist">

@ -107,6 +107,8 @@
<item name="android:colorBackground">@color/black</item> <item name="android:colorBackground">@color/black</item>
<item name="android:colorForeground">@color/white</item> <item name="android:colorForeground">@color/white</item>
<item name="android:colorBackgroundCacheHint">@null</item> <item name="android:colorBackgroundCacheHint">@null</item>
<!-- chips should be dark, not black -->
<item name="chipStyle">@style/Widget.Material.Chip.Choice.Dark</item>
</style> </style>
<style name="Widget.Material.Chip.Choice.Dark" parent="Widget.MaterialComponents.Chip.Action"> <style name="Widget.Material.Chip.Choice.Dark" parent="Widget.MaterialComponents.Chip.Action">

Loading…
Cancel
Save