mirror of
https://github.com/akaessens/NoFbEventScraper
synced 2025-06-05 23:29:13 +02:00
switch to webview display in help and about
add icons to overflow menu add settings with scrape url prefix selection rewrite help and about
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.akdev.nofbeventscraper;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
@ -7,6 +8,7 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
@ -15,19 +17,14 @@ public class AboutActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
this.getSupportActionBar().hide();
|
||||
ActionBar action_bar = getSupportActionBar();
|
||||
if (action_bar != null) {
|
||||
action_bar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
ImageView img = (ImageView)findViewById(R.id.paypal_image);
|
||||
WebView webview_about = findViewById(R.id.webview_about);
|
||||
|
||||
img.setOnClickListener(new View.OnClickListener(){
|
||||
public void onClick(View v){
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.addCategory(Intent.CATEGORY_BROWSABLE);
|
||||
intent.setData(Uri.parse("https://www.paypal.me/andreaskaessens"));
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
webview_about.loadUrl("file:////android_asset/about.html");
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.akdev.nofbeventscraper;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.text.Editable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
@ -54,12 +57,21 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
// check for url format
|
||||
new URL(url).toURI();
|
||||
|
||||
Pattern pattern = Pattern.compile("(facebook.com/events/[0-9]*)");
|
||||
String regex = "(facebook.com/events/[0-9]*)(/\\?event_time_id=[0-9]*)?";
|
||||
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(url);
|
||||
|
||||
if (matcher.find()) {
|
||||
|
||||
SharedPreferences shared_prefs = PreferenceManager.getDefaultSharedPreferences(main.get());
|
||||
String url_prefix = shared_prefs.getString("url_preference", "m.facebook.com");
|
||||
// rewrite url to m.facebook and dismiss any query strings or referrals
|
||||
return "https://m." + matcher.group(1);
|
||||
String ret = url_prefix + matcher.group(1);
|
||||
if (matcher.group(2) != null) {
|
||||
ret += matcher.group(2);
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
throw new URISyntaxException(url, "Does not contain event.");
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.akdev.nofbeventscraper;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class HelpActivity extends AppCompatActivity {
|
||||
@ -10,6 +12,14 @@ public class HelpActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_help);
|
||||
this.getSupportActionBar().hide();
|
||||
ActionBar action_bar = getSupportActionBar();
|
||||
if (action_bar != null) {
|
||||
action_bar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
WebView webview_help = findViewById(R.id.webview_help);
|
||||
|
||||
webview_help.loadUrl("file:////android_asset/help.html");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.view.menu.MenuBuilder;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
@ -320,6 +321,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
|
||||
if(menu instanceof MenuBuilder){
|
||||
MenuBuilder m = (MenuBuilder) menu;
|
||||
//noinspection RestrictedApi
|
||||
m.setOptionalIconsVisible(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -339,6 +346,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(new Intent(this, HelpActivity.class));
|
||||
return true;
|
||||
}
|
||||
if (id == R.id.action_settings) {
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.akdev.nofbeventscraper;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.settings_activity);
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.settings, new SettingsFragment())
|
||||
.commit();
|
||||
ActionBar action_bar = getSupportActionBar();
|
||||
if (action_bar != null) {
|
||||
action_bar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user