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

simplifications and refactors

This commit is contained in:
TrianguloY 2023-01-28 19:29:24 +01:00
parent 5ace0d6f98
commit 4c723b8bff
10 changed files with 227 additions and 220 deletions

View File

@ -27,8 +27,10 @@ public class MainActivity extends Activity {
AndroidSettings.setTheme(this, false);
AndroidSettings.setLocale(this);
setContentView(R.layout.activity_main);
if (!TutorialActivity.TUTORIAL(this).get()){
openTutorial(this.getCurrentFocus());
// open tutorial if not done yet
if (!TutorialActivity.DONE(this).get()) {
PackageUtils.startActivity(new Intent(this, TutorialActivity.class), R.string.toast_noApp, this);
}
}
@ -69,8 +71,4 @@ public class MainActivity extends Activity {
Toast.makeText(this, getString(R.string.app_name) + " - " + getString(R.string.trianguloy), Toast.LENGTH_SHORT).show();
}
public void openTutorial(View view){
PackageUtils.startActivity(new Intent(this, TutorialActivity.class), R.string.toast_noApp, this);
}
}

View File

@ -1,19 +1,13 @@
package com.trianguloy.urlchecker.activities;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.role.RoleManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import com.trianguloy.urlchecker.R;
import com.trianguloy.urlchecker.utilities.AndroidSettings;
@ -106,6 +100,7 @@ public class SettingsActivity extends Activity {
}
/* ------------------- tutorial ------------------- */
public void openTutorial(View view){
PackageUtils.startActivity(new Intent(this, TutorialActivity.class), R.string.toast_noApp, this);
}

View File

@ -14,16 +14,18 @@ import com.trianguloy.urlchecker.utilities.AndroidSettings;
import com.trianguloy.urlchecker.utilities.GenericPref;
import com.trianguloy.urlchecker.utilities.PackageUtils;
import java.util.Locale;
public class TutorialActivity extends Activity {
private Button backButton;
private Button prevButton;
private Button nextButton;
private GenericPref.Bool tutorialDone;
private ViewFlipper flipper;
private TextView pageIndexText;
public static GenericPref.Bool TUTORIAL(Context cntx) {
return new GenericPref.Bool("tutorial_done", true, cntx);
public static GenericPref.Bool DONE(Context cntx) {
return new GenericPref.Bool("tutorial_done", false, cntx);
}
@Override
@ -34,51 +36,72 @@ public class TutorialActivity extends Activity {
setContentView(R.layout.activity_tutorial);
setTitle(R.string.tutorial);
flipper = findViewById(R.id.flipper);
backButton = findViewById(R.id.bBack);
nextButton = findViewById(R.id.bNext);
tutorialDone = DONE(this);
flipper = findViewById(R.id.flipper);
prevButton = findViewById(R.id.bBack);
nextButton = findViewById(R.id.bNext);
pageIndexText = findViewById(R.id.pageIndex);
checkEnabled();
updateButtons();
tutorialDone = TUTORIAL(this);
}
/* ------------------- buttons ------------------- */
// ------------------- buttons -------------------
public void nextSlide(View view){
flipper.showNext();
checkEnabled();
@Override
public void onBackPressed() {
prev(null);
}
public void previousSlide(View view){
flipper.showPrevious();
checkEnabled();
public void prev(View view) {
if (flipper.getDisplayedChild() == 0) {
// first page, exit
exit();
} else {
// show prev
flipper.showPrevious();
updateButtons();
}
}
public void next(View view) {
if (flipper.getDisplayedChild() == flipper.getChildCount() - 1) {
// last page, exit
exit();
} else {
// show next
flipper.showNext();
updateButtons();
}
}
/* ------------------- actions ------------------- */
/**
* Checks if the buttons should be enabled depending on the current page
* If on last page "next" will be disabled, if on first page "back" will be disabled
* Also sets index text
* Updates the buttons and index texts
*/
private void checkEnabled(){
private void updateButtons() {
int current = flipper.getDisplayedChild();
int max = flipper.getChildCount();
backButton.setEnabled(current != 0);
nextButton.setEnabled(current != max - 1);
prevButton.setText(current == 0 ? R.string.tutorial_button_skip : R.string.back);
nextButton.setText(current != max - 1 ? R.string.next : R.string.tutorial_button_end);
pageIndexText.setText(String.format("%d/%d", current + 1, max));
pageIndexText.setText(String.format(Locale.getDefault(), "%d/%d", current + 1, max));
}
public void openModulesActivity(View view) {
PackageUtils.startActivity(new Intent(this, ModulesActivity.class), R.string.toast_noApp, this);
}
public void finishTutorial(View view){
/**
* Marks the tutorial as completed and exits
*/
private void exit() {
tutorialDone.set(true);
this.finish();
}
// TODO: replace with 'fragment' listener
public void openModulesActivity(View view) {
PackageUtils.startActivity(new Intent(this, ModulesActivity.class), R.string.toast_noApp, this);
}
}

View File

@ -12,10 +12,22 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/txt_openLinks" />
android:onClick="openTutorial"
android:text="@string/btn_tutorialSettings" /><FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/padding">
<include layout="@layout/separator" />
</FrameLayout><TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/txt_openLinks" />
<fragment
android:id="@+id/browser_buttons"
@ -65,23 +77,6 @@
android:layout_height="wrap_content" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/padding"
android:paddingBottom="@dimen/padding">
<include layout="@layout/separator" />
</FrameLayout>
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="openTutorial"
android:text="@string/btn_tutorialSettings" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -11,33 +11,150 @@
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
android:layout_weight="1"
android:autoStart="false">
<include
android:id="@+id/tutorial_flipper_intro"
layout="@layout/view_tutorial_intro"
<ScrollView
android:id="@+id/p1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent">
<include
android:id="@+id/tutorial_flipper_app"
layout="@layout/view_tutorial_app"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<include
android:id="@+id/tutorial_flipper_modules"
layout="@layout/view_tutorial_modules"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher" /><TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/app_name"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" /><TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding"
android:gravity="center"
android:text="@string/tutorial_txt_intro" />
<include
android:id="@+id/tutorial_flipper_tips"
layout="@layout/view_tutorial_tips"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ViewFlipper>
</ScrollView><ScrollView
android:id="@+id/p2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/tutorial_txt_app" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding"
android:gravity="center"
android:text="@string/txt_openLinks" />
<fragment
android:id="@+id/browser_buttons"
class="com.trianguloy.urlchecker.fragments.BrowserButtonsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools: layout="@layout/fragment_browser_buttons" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding"
android:autoLink="web"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:linksClickable="false"
android:text="@string/txt_sample" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:gravity="center"
android:minHeight="48dp"
android:padding="@dimen/smallPadding"
android:text="@string/sample_url" />
</LinearLayout>
</ScrollView><ScrollView
android:id="@+id/p3"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/tutorial_txt_modules" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/padding"
android:drawableStart="@android:drawable/ic_menu_sort_by_size"
android:drawableLeft="@android:drawable/ic_menu_sort_by_size"
android:drawablePadding="@dimen/smallPadding"
android:onClick="openModulesActivity"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:text="@string/a_modules" />
</LinearLayout>
</ScrollView><ScrollView
android:id="@+id/p4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/tutorial_txt_tips" />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<LinearLayout
android:layout_width="match_parent"
@ -50,15 +167,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="previousSlide"
android:text="@string/back" />
android:onClick="prev"
android:text="&lt;" />
<TextView
android:id="@+id/pageIndex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical" />
android:gravity="center_horizontal|center_vertical"
android:text="/" />
<Button
android:id="@+id/bNext"
@ -66,8 +184,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="nextSlide"
android:text="@string/next" />
android:onClick="next"
android:text="&gt;" />
</LinearLayout>
</LinearLayout>

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tutorial_txt_app" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smallPadding"
android:text="@string/txt_openLinks" />
<fragment
android:id="@+id/browser_buttons"
class="com.trianguloy.urlchecker.fragments.BrowserButtonsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_browser_buttons" />
</LinearLayout>
</ScrollView>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tutorial_txt_intro" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding"
android:onClick="finishTutorial"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:text="@string/tutorial_button_skip" />
</LinearLayout>
</ScrollView>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tutorial_txt_modules" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/padding"
android:drawableStart="@android:drawable/ic_menu_sort_by_size"
android:drawableLeft="@android:drawable/ic_menu_sort_by_size"
android:drawablePadding="@dimen/smallPadding"
android:onClick="openModulesActivity"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:text="@string/a_modules" />
</LinearLayout>
</ScrollView>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tutorial_txt_tips" />
<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding"
android:onClick="finishTutorial"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:text="@string/tutorial_button_end" />
</LinearLayout>
</ScrollView>

View File

@ -54,15 +54,19 @@ Translations: %s."</string>
This is the tutorial, if you want to skip it you can do so with the button below. You can always come back to this tutorial from the settings menu."</string>
<string name="tutorial_txt_app">"The app acts as an intermediary when opening or sharing url links. Once an url is sent to the app you can interact with it via the modules. After that you can open the link (in the app you want), share it or copy it to the clipboard.
For the app to intercept the urls when opening them we need to set it up as a browser first. This is not needed if you intent to pass the urls using the share functionality."</string>
<string name="tutorial_txt_modules">"The modules are the way the app interacts with the urls. There are multiple modules, each of them have a specific function, usually they either give you information about the url, or modify it. It is recommended you check them in the modules menu as each one is explained there and you can also change their behaviour.
For the app to intercept the urls when opening them we need to set it up as the default browser first. This is not needed if you intent to pass the urls using the share functionality."</string>
<string name="tutorial_txt_modules">"The modules are the way the app interacts with the urls. There are multiple modules, each of them with a specific function, usually they either give you information about the url, or allow to modify it. They are quite configurable so it is recommended you check them and adapt as needed. Each one is explained there.
If you want you can go to the modules menu by tapping the button below."</string>
<string name="tutorial_txt_tips">"That's all. Here are some tips that can be useful.
Important: all the actions are manual by default, the app won't modify anything nor connect to the Internet unless you specifically allow it, but some actions can be configured to apply automatically if desired.
When an app doesn't give you a way to open or share a url, but it gives you a way to do the other you can solve the issue using this app. You can also copy the url to the clipboard.
You can open the list of modules from the main screen, or by tapping the button below."</string>
<string name="tutorial_txt_tips">"That's all. Here are some tips that can be useful:
There are some urls which its only purpose is redirecting you to another url. If the final url can be opened in an app, then you can avoid opening it in a browser."</string>
When an app doesn't give you a way to open or share a url, but it gives you a way to do the other you can solve the issue using this app. You can also copy the url to the clipboard by long pressing the share button.
There are some urls which its only purpose is redirecting you to another url. If the final url can be opened in an app, then you can avoid opening it in a browser.
Hope you find the app useful! And don't hesitate to suggest features, report bugs or even propose changes. Find all relevant links on the about screen."</string>
<string name="tutorial_button_skip">Skip tutorial</string>
<string name="tutorial_button_end">Finish tutorial</string>
@ -79,15 +83,14 @@ There are some urls which its only purpose is redirecting you to another url. If
<string name="share">Share</string>
<string name="canceled">Canceled</string>
<string name="deviceDefault">Device default</string>
<string name="next">Next</string>
<string name="back">Back</string>
<string name="json_desc">[Beta feature] This is an advanced editor, the content must be formatted into valid JSON. You can press the top-right button to format and validate it.</string>
<string name="json_edit">Advanced editor</string>
<string name="next">Next</string>
<string name="back">Back</string>
<!-- modules -->
<string name="mPttrn_name">Patterns checker</string>
<string name="mPttrn_desc">"This module checks the url with regexp patterns that warns, suggests or applies replacements. You can modify or create your own patterns, or even use user-created ones.