commit 065cc04667bbc46a568dabd888d52489560b78e8 Author: akaessens <24660231+akaessens@users.noreply.github.com> Date: Wed Mar 25 18:24:07 2020 +0100 initial version for NoFb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..c3a998a --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +NoFb Event Scraper \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..440480e --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..15aa2ef --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,41 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + applicationId "com.akdev.nofbeventscraper" + minSdkVersion 26 + targetSdkVersion 29 + versionCode 1 + versionName "0.1" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.navigation:navigation-fragment:2.2.1' + implementation 'androidx.navigation:navigation-ui:2.2.1' + + // jsoup HTML parser library @ https://jsoup.org/ + implementation 'org.jsoup:jsoup:1.11.1' + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/akdev/nofbeventscraper/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/akdev/nofbeventscraper/ExampleInstrumentedTest.java new file mode 100644 index 0000000..2405c95 --- /dev/null +++ b/app/src/androidTest/java/com/akdev/nofbeventscraper/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.akdev.nofbeventscraper; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.akdev.nofbeventscraper", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..82f55a8 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/akdev/nofbeventscraper/FbEvent.java b/app/src/main/java/com/akdev/nofbeventscraper/FbEvent.java new file mode 100644 index 0000000..1bbcf48 --- /dev/null +++ b/app/src/main/java/com/akdev/nofbeventscraper/FbEvent.java @@ -0,0 +1,19 @@ +package com.akdev.nofbeventscraper; + +public class FbEvent { + public String name; + public String start_date; + public String end_date; + public String description; + public String location; + public String image_url; + + public FbEvent (String name, String start_date, String end_date, String description, String location, String image_url) { + this.name = name; + this.start_date = start_date; + this.end_date = end_date; + this.description = description; + this.location = location; + this.image_url = image_url; + } +} diff --git a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java new file mode 100644 index 0000000..f992f24 --- /dev/null +++ b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java @@ -0,0 +1,92 @@ +package com.akdev.nofbeventscraper; + +import android.os.AsyncTask; +import android.util.Log; +import android.view.View; + +import com.google.android.material.textfield.TextInputEditText; + +import org.json.JSONException; +import org.json.JSONObject; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.io.IOException; + +public class FbScraper extends AsyncTask { + + private String url; + private View popupView; + public FbEvent event; + + public FbScraper(View popupView, String url) { + this.url = url; + this.popupView = popupView; + } + + @Override + protected Void doInBackground(Void... voids){ + + Document document = null; + + try { + document = Jsoup.connect(url).get(); + + Log.d("url", url); + + //String event_name = document.title(); + + String json = document.select("#u_0_j").first().data(); + + try { + JSONObject reader = new JSONObject(json); + + String event_name = reader.getString("name"); + String event_start = reader.getString("startDate"); + String event_end = reader.getString("endDate"); + String event_description = reader.getString("description"); + String location = reader.getJSONObject("location").getString("name"); + + + String image_url = reader.getString("image"); + + this.event = new FbEvent(event_name, event_start, event_end, event_description, location, image_url); + + } catch (JSONException e) { + e.printStackTrace(); + } + + + + + } catch (IOException e) { + e.printStackTrace(); + } + + + + + + + + return null; + } + + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + + TextInputEditText field_name = (TextInputEditText) this.popupView.findViewById(R.id.field_event_name); + TextInputEditText field_start = (TextInputEditText) this.popupView.findViewById(R.id.field_event_start); + TextInputEditText field_end = (TextInputEditText) this.popupView.findViewById(R.id.field_event_end); + TextInputEditText field_location = (TextInputEditText) this.popupView.findViewById(R.id.field_event_location); + + field_name.setText(event.name); + field_start.setText(event.start_date); + field_end.setText(event.end_date); + field_location.setText(event.location); + + } +} + diff --git a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java new file mode 100644 index 0000000..6b43bbb --- /dev/null +++ b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java @@ -0,0 +1,172 @@ +package com.akdev.nofbeventscraper; + + +import android.content.ClipboardManager; +import android.content.Context; + +import android.content.Intent; +import android.os.Bundle; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import com.google.android.material.textfield.TextInputEditText; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import android.provider.CalendarContract; +import android.view.Gravity; +import android.view.LayoutInflater; + +import android.view.View; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.Button; + +import android.widget.LinearLayout; +import android.widget.PopupWindow; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Calendar; + + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + FloatingActionButton fab = findViewById(R.id.fab); + + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + onButtonShowPopupWindowClick(view); + } + }); + } + + @Override + 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); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } + + public void onButtonShowPopupWindowClick(View view) { + + // inflate the layout of the popup window + LayoutInflater inflater = (LayoutInflater) + getSystemService(LAYOUT_INFLATER_SERVICE); + final View popupView = inflater.inflate(R.layout.popup_window, null); + + // create the popup window + int width = LinearLayout.LayoutParams.WRAP_CONTENT; + int height = LinearLayout.LayoutParams.WRAP_CONTENT; + boolean focusable = true; // lets taps outside the popup also dismiss it + final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable); + + // show the popup window + // which view you pass in doesn't matter, it is only used for the window token + popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0); + + Button cancel_button = (Button)popupView.findViewById(R.id.cancel_button); + cancel_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + popupWindow.dismiss(); + } + }); + + Button ok_button = (Button)popupView.findViewById(R.id.ok_button); + ok_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + TextInputEditText uri_input = (TextInputEditText) popupView.findViewById(R.id.text_input); + TextInputEditText field_name = (TextInputEditText) popupView.findViewById(R.id.field_event_name); + TextInputEditText field_start = (TextInputEditText) popupView.findViewById(R.id.field_event_start); + TextInputEditText field_end = (TextInputEditText) popupView.findViewById(R.id.field_event_end); + TextInputEditText field_location = (TextInputEditText) popupView.findViewById(R.id.field_event_location); + + + // time + String start_str = field_start.getText().insert(22, ":").toString(); + String end_str = field_end.getText().insert(22, ":").toString(); + + LocalDateTime start = LocalDateTime.parse(start_str, DateTimeFormatter.ISO_OFFSET_DATE_TIME); + LocalDateTime end = LocalDateTime.parse(end_str, DateTimeFormatter.ISO_OFFSET_DATE_TIME); + + ZoneId zoneId = ZoneId.systemDefault(); + long start_epoch = start.atZone(zoneId).toEpochSecond()*1000; + long end_epoch = end.atZone(zoneId).toEpochSecond()*1000; + + //Calendar calendar = Calendar.getInstance(); + + + Intent intent = new Intent(Intent.ACTION_EDIT); + intent.setType("vnd.android.cursor.item/event"); + intent.putExtra(CalendarContract.Events.TITLE, field_name.getText().toString()); + intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start_epoch); + intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end_epoch); + intent.putExtra(CalendarContract.Events.EVENT_LOCATION, field_location.getText().toString()); + intent.putExtra(CalendarContract.EXTRA_CUSTOM_APP_URI, uri_input.getText().toString()); + startActivity(intent); + + popupWindow.dismiss(); + } + }); + + Button paste_button = (Button)popupView.findViewById(R.id.paste_button); + final TextInputEditText text_input = (TextInputEditText) popupView.findViewById(R.id.text_input); + + paste_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + + if (clipboard != null) { + String str = clipboard.getPrimaryClip().getItemAt(0).getText().toString(); + + str = "https://m.facebook.com/events/2402761143327832/"; + text_input.setText(str); + } + + FbScraper scraper = new FbScraper(popupView, text_input.getText().toString()); + + FbEvent event; + + scraper.execute(); + } + }); + + /* dismiss the popup window when touched + popupView.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + popupWindow.dismiss(); + return true; + } + });*/ + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..45dcef4 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml new file mode 100644 index 0000000..8978828 --- /dev/null +++ b/app/src/main/res/layout/content_main.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/app/src/main/res/layout/popup_window.xml b/app/src/main/res/layout/popup_window.xml new file mode 100644 index 0000000..f1fda50 --- /dev/null +++ b/app/src/main/res/layout/popup_window.xml @@ -0,0 +1,180 @@ + + + + + + + + + + + +