0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

New drawer module #252

Solves #224.

Not much to explain really, modules that can be hidden are in a separate layout that can change its visibility. The module itself has a button to toggle the visibility.
This commit is contained in:
TrianguloY 2023-07-26 18:44:43 +02:00 committed by GitHub
commit f4c494471c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 211 additions and 15 deletions

View File

@ -19,6 +19,7 @@ import com.trianguloy.urlchecker.R;
import com.trianguloy.urlchecker.modules.AModuleData;
import com.trianguloy.urlchecker.modules.AModuleDialog;
import com.trianguloy.urlchecker.modules.ModuleManager;
import com.trianguloy.urlchecker.modules.list.DrawerModule;
import com.trianguloy.urlchecker.url.UrlData;
import com.trianguloy.urlchecker.utilities.AndroidSettings;
import com.trianguloy.urlchecker.utilities.AndroidUtils;
@ -135,6 +136,18 @@ public class MainDialog extends Activity {
}
}
// fourth finish notification
for (var module : modules.keySet()) {
// skip own if required
if (!urlData.triggerOwn && module == urlData.trigger) continue;
try {
module.onFinishUrl(urlData);
} catch (Exception e) {
e.printStackTrace();
AndroidUtils.assertError("Exception in onFinishUrl for module " + module.getClass().getName());
}
}
break;
}
@ -165,7 +178,8 @@ public class MainDialog extends Activity {
// ------------------- initialize -------------------
private LinearLayout ll_mods;
private LinearLayout ll_main;
private LinearLayout ll_drawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -177,7 +191,9 @@ public class MainDialog extends Activity {
setFinishOnTouchOutside(true);
// get views
ll_mods = findViewById(R.id.middle_modules);
ll_main = findViewById(R.id.main);
ll_drawer = findViewById(R.id.drawer);
ll_drawer.setVisibility(View.GONE);
// load url (or urls)
var links = getOpenUrl();
@ -219,17 +235,22 @@ public class MainDialog extends Activity {
*/
private void initializeModules() {
modules.clear();
ll_mods.removeAllViews();
ll_main.removeAllViews();
ll_drawer.removeAllViews();
var placeOnDrawer = false;
// add
final List<AModuleData> middleModules = ModuleManager.getModules(false, this);
for (AModuleData module : middleModules) {
initializeModule(module);
var middleModules = ModuleManager.getModules(false, this);
for (var module : middleModules) {
initializeModule(module, placeOnDrawer);
// If this module is the drawer module, all the remaining modules will be hidden
if (module instanceof DrawerModule) placeOnDrawer = true;
}
// avoid empty
if (ll_mods.getChildCount() == 0) {
ll_mods.addView(egg());
if (ll_main.getChildCount() == 0) {
ll_main.addView(egg()); // ;)
}
}
@ -238,7 +259,7 @@ public class MainDialog extends Activity {
*
* @param moduleData which module to initialize
*/
private void initializeModule(AModuleData moduleData) {
private void initializeModule(AModuleData moduleData, boolean drawer) {
try {
// enabled, add
AModuleDialog module = moduleData.getDialog(this);
@ -248,22 +269,23 @@ public class MainDialog extends Activity {
// set content if required
var views = new ArrayList<View>();
var ll = drawer ? ll_drawer : ll_main;
if (layoutId >= 0) {
// separator if necessary
if (ll_mods.getChildCount() != 0) views.add(addSeparator());
if (ll_main.getChildCount() != 0) views.add(addSeparator(ll));
ViewGroup parent;
// set module block
if (ModuleManager.getDecorationsPrefOfModule(moduleData, this).get()) {
// init decorations
View block = Inflater.inflate(R.layout.dialog_module, ll_mods);
final TextView title = block.findViewById(R.id.title);
var block = Inflater.inflate(R.layout.dialog_module, ll);
var title = block.<TextView>findViewById(R.id.title);
title.setText(getString(R.string.dd, getString(moduleData.getName())));
parent = block.findViewById(R.id.mod);
} else {
// no decorations
parent = ll_mods;
parent = ll;
}
// set module content
@ -290,8 +312,8 @@ public class MainDialog extends Activity {
/**
* Adds a separator component to the list of mods
*/
private View addSeparator() {
return Inflater.inflate(R.layout.separator, ll_mods);
private View addSeparator(LinearLayout ll) {
return Inflater.inflate(R.layout.separator, ll);
}
/**
@ -322,6 +344,35 @@ public class MainDialog extends Activity {
}
}
// ------------------- drawer module -------------------
/**
* returns the visibility of the drawer
*/
public boolean isDrawerVisible() {
return ll_drawer.getVisibility() != View.GONE;
}
/**
* Toggles the drawer visibility
*/
public void toggleDrawer() {
ll_drawer.setVisibility(isDrawerVisible() ? View.GONE : View.VISIBLE);
}
/**
* returns true if the drawer contains at least one visible children
*/
public boolean anyDrawerChildVisible() {
int childCount = ll_drawer.getChildCount();
for (int i = 0; i < childCount; i++) {
if (ll_drawer.getChildAt(i).getVisibility() == View.VISIBLE) {
return true;
}
}
return false;
}
/* ------------------- its a secret! ------------------- */
/**

View File

@ -46,6 +46,12 @@ public abstract class AModuleDialog implements Fragment {
public void onDisplayUrl(UrlData urlData) {
}
/**
* Last call for any update a module may need (like the drawer module needing to know how many modules are visible).
*/
public void onFinishUrl(UrlData urlData) {
}
// ------------------- utilities -------------------
/**

View File

@ -4,6 +4,7 @@ import android.content.Context;
import com.trianguloy.urlchecker.modules.list.ClearUrlModule;
import com.trianguloy.urlchecker.modules.list.DebugModule;
import com.trianguloy.urlchecker.modules.list.DrawerModule;
import com.trianguloy.urlchecker.modules.list.FlagsModule;
import com.trianguloy.urlchecker.modules.list.HistoryModule;
import com.trianguloy.urlchecker.modules.list.HostsModule;
@ -50,6 +51,9 @@ public class ModuleManager {
modules.add(new DebugModule());
modules.add(new OpenModule());
// by default the drawer module should not hide other modules, so it must be the last
modules.add(new DrawerModule());
}
/* ------------------- order ------------------- */

View File

@ -0,0 +1,81 @@
package com.trianguloy.urlchecker.modules.list;
import android.view.View;
import android.widget.ImageView;
import com.trianguloy.urlchecker.R;
import com.trianguloy.urlchecker.activities.ModulesActivity;
import com.trianguloy.urlchecker.dialogs.MainDialog;
import com.trianguloy.urlchecker.modules.AModuleConfig;
import com.trianguloy.urlchecker.modules.AModuleData;
import com.trianguloy.urlchecker.modules.AModuleDialog;
import com.trianguloy.urlchecker.modules.DescriptionConfig;
import com.trianguloy.urlchecker.url.UrlData;
import com.trianguloy.urlchecker.utilities.AndroidUtils;
/**
* A special module that manages the drawer functionality
*/
public class DrawerModule extends AModuleData {
@Override
public String getId() {
return "drawer";
}
@Override
public int getName() {
return R.string.mDrawer_name;
}
@Override
public boolean isEnabledByDefault() {
return false;
}
@Override
public AModuleDialog getDialog(MainDialog cntx) {
return new DrawerDialog(cntx);
}
@Override
public AModuleConfig getConfig(ModulesActivity cntx) {
return new DescriptionConfig(R.string.mDrawer_desc);
}
}
class DrawerDialog extends AModuleDialog {
private ImageView buttonL;
private ImageView buttonR;
private final MainDialog dialog;
public DrawerDialog(MainDialog dialog) {
super(dialog);
this.dialog = dialog;
}
@Override
public int getLayoutId() {
return R.layout.dialog_drawer;
}
@Override
public void onInitialize(View views) {
buttonL = views.findViewById(R.id.drawerL);
buttonR = views.findViewById(R.id.drawerR);
var parent = views.findViewById(R.id.parent);
parent.getBackground().setAlpha(25);
AndroidUtils.toggleableListener(parent, v -> dialog.toggleDrawer(), v -> {
buttonL.setImageResource(dialog.isDrawerVisible() ?
R.drawable.arrow_down : R.drawable.arrow_right);
buttonR.setImageResource(dialog.isDrawerVisible() ?
R.drawable.arrow_down : R.drawable.arrow_right);
});
}
@Override
public void onFinishUrl(UrlData urlData) {
setVisibility(dialog.anyDrawerChildVisible());
}
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="@dimen/padding"
android:layout_marginLeft="@dimen/padding"
android:layout_marginTop="@dimen/smallPadding"
android:layout_marginEnd="@dimen/padding"
android:layout_marginRight="@dimen/padding"
android:layout_marginBottom="@dimen/smallPadding"
android:background="@drawable/round_box"
android:backgroundTint="?attr/colorAccent"
android:gravity="center|center_vertical"
android:weightSum="2">
<ImageView
android:id="@+id/drawerL"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/arrow_down"
android:tint="?attr/colorAccent" />
<ImageView
android:id="@+id/drawerR"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scaleX="-1"
android:src="@drawable/arrow_down"
android:tint="?attr/colorAccent" />
</LinearLayout>

View File

@ -20,6 +20,22 @@
<requestFocus
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>

View File

@ -325,4 +325,7 @@ You can also click the 'X' button to remove some of them.
This is an advanced version of the 'Queries Remover' module."</string>
<string name="mParts_empty">(empty)</string>
<string name="mParts_copy">Part copied to clipboard</string>
<!-- -->
<string name="mDrawer_name">Drawer</string>
<string name="mDrawer_desc">All modules below this will be hidden in a drawer. The modules will still work, but are stored in the drawer, you can store modules here to avoid clutter of modules you do not always need.</string>
</resources>