include card view, add app bars

This commit is contained in:
akaessens 2020-09-04 14:51:39 +02:00
parent 926c2c612a
commit 85e9c15f5e
5 changed files with 109 additions and 239 deletions

View File

@ -26,6 +26,7 @@ android {
dependencies { dependencies {
'androidx.coordinatorlayout:coordinatorlayout:1.1.0' 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])

View File

@ -18,10 +18,14 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.menu.MenuBuilder; import androidx.appcompat.view.menu.MenuBuilder;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSnapHelper;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SnapHelper;
import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
@ -36,18 +40,17 @@ import static com.akdev.nofbeventscraper.FbEvent.dateTimeToEpoch;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
protected Button ok_button; protected Button ok_button;
protected Button paste_button; protected ExtendedFloatingActionButton paste_button;
protected TextInputEditText edit_text_uri_input; protected TextInputEditText edit_text_uri_input;
protected TextInputLayout layout_uri_input; protected TextInputLayout layout_uri_input;
protected ImageView image_view_toolbar;
protected CollapsingToolbarLayout layout_toolbar;
protected FbScraper scraper; protected FbScraper scraper;
protected List<FbEvent> events; protected List<FbEvent> events;
EventAdapter adapter; EventAdapter adapter;
LinearLayoutManager linear_layout_manager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -57,7 +60,10 @@ public class MainActivity extends AppCompatActivity {
edit_text_uri_input = (TextInputEditText) findViewById(R.id.edit_text_uri_input); edit_text_uri_input = (TextInputEditText) findViewById(R.id.edit_text_uri_input);
layout_uri_input = (TextInputLayout) findViewById(R.id.layout_uri_input); layout_uri_input = (TextInputLayout) findViewById(R.id.layout_uri_input);
// Lookup the recyclerview in activity layout // Lookup the recyclerview in activity layout
RecyclerView recycler_view = (RecyclerView) findViewById(R.id.recycler_view); final RecyclerView recycler_view = (RecyclerView) findViewById(R.id.recycler_view);
SnapHelper snap_helper = new LinearSnapHelper();
snap_helper.attachToRecyclerView(recycler_view);
// Initialize contacts // Initialize contacts
events = createEventList(3); events = createEventList(3);
@ -67,55 +73,29 @@ public class MainActivity extends AppCompatActivity {
// Attach the adapter to the recyclerview to populate items // Attach the adapter to the recyclerview to populate items
recycler_view.setAdapter(adapter); recycler_view.setAdapter(adapter);
// Set layout manager to position the items // Set layout manager to position the items
recycler_view.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
linear_layout_manager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recycler_view.setLayoutManager(linear_layout_manager);
recycler_view.setHasFixedSize(true);
// That's all! // That's all!
/*Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
//ok_button = (Button) findViewById(R.id.ok_button); ok_button = (Button) findViewById(R.id.ok_button);
paste_button = (Button) findViewById(R.id.paste_button); paste_button = (ExtendedFloatingActionButton) findViewById(R.id.paste_button);
layout_toolbar = (CollapsingToolbarLayout) findViewById(R.id.layout_toolbar);
image_view_toolbar = (ImageView) findViewById(R.id.image_view);*/
/* /*
* Default view settings * Default view settings
*/ */
//ok_button.setEnabled(false); ok_button.setEnabled(false);
//layout_event_location.setEndIconVisible(false);
//image_view_toolbar.setImageResource(R.drawable.ic_banner_foreground);
/*
* Display title only when toolbar is collapsed
*/
/*AppBarLayout app_bar_layout = (AppBarLayout) findViewById(R.id.app_bar);
app_bar_layout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean show = true;
int scroll_range = -1;
@Override
public void onOffsetChanged(AppBarLayout app_bar_layout, int vertical_offset) {
if (scroll_range == -1) {
scroll_range = app_bar_layout.getTotalScrollRange();
}
if (scroll_range + vertical_offset == 0) {
layout_toolbar.setTitle(getString(R.string.app_name));
show = true;
} else if (show) {
layout_toolbar.setTitle(" ");
show = false;
}
}
});
/* /*
* Paste button: get last entry from clipboard * Paste button: get last entry from clipboard
*/ */
/*paste_button.setOnClickListener(new View.OnClickListener() { paste_button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -166,10 +146,12 @@ public class MainActivity extends AppCompatActivity {
/* /*
* Add to calendar button: launch calendar application * Add to calendar button: launch calendar application
*/ */
/*ok_button.setOnClickListener(new View.OnClickListener() { ok_button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
FbEvent event = events.get(linear_layout_manager.findFirstCompletelyVisibleItemPosition());
Long start_epoch = dateTimeToEpoch(event.start_date); Long start_epoch = dateTimeToEpoch(event.start_date);
Long end_epoch = dateTimeToEpoch(event.end_date); Long end_epoch = dateTimeToEpoch(event.end_date);
@ -188,7 +170,7 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
} }
});*/ });
/* /*
* Enter button in uri input: start scraping * Enter button in uri input: start scraping
@ -271,6 +253,7 @@ public class MainActivity extends AppCompatActivity {
edit_text_event_description.setError(null);*/ edit_text_event_description.setError(null);*/
this.events.clear(); this.events.clear();
adapter.notifyDataSetChanged();
try { try {
scraper.cancel(true); scraper.cancel(true);
@ -280,7 +263,7 @@ public class MainActivity extends AppCompatActivity {
} }
/*ok_button.setEnabled(false); ok_button.setEnabled(false);/*
layout_event_location.setEndIconVisible(false); layout_event_location.setEndIconVisible(false);
image_view_toolbar.setImageResource(R.drawable.ic_banner_foreground);*/ image_view_toolbar.setImageResource(R.drawable.ic_banner_foreground);*/
} }
@ -293,9 +276,10 @@ public class MainActivity extends AppCompatActivity {
*/ */
public void update(List<FbEvent> events) { public void update(List<FbEvent> events) {
this.events.addAll(0, events); this.events.clear();
this.events.addAll(events);
adapter.notifyItemInserted(0); adapter.notifyDataSetChanged();
/*edit_text_uri_input.setText(event.url); /*edit_text_uri_input.setText(event.url);
@ -304,9 +288,9 @@ public class MainActivity extends AppCompatActivity {
Picasso.get() Picasso.get()
.load(event.image_url) .load(event.image_url)
.placeholder(R.drawable.ic_banner_foreground) .placeholder(R.drawable.ic_banner_foreground)
.into(image_view_toolbar); .into(image_view_toolbar);*/
ok_button.setEnabled(true);*/ ok_button.setEnabled(true);
} }

View File

@ -1,13 +1,68 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="NoFb Event Scraper" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/paste_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="64dp"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:icon="@drawable/ic_content_paste"
android:tooltipText="@string/tooltip_paste"
tools:ignore="UnusedAttribute" />
<include layout="@layout/content_main" /> <include layout="@layout/content_main" />
</RelativeLayout> <com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<Button
android:id="@+id/ok_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:padding="12dp"
android:text="@string/button_add"
android:textColor="#FFFFFF"
app:cornerRadius="24dp"
app:icon="@drawable/ic_event_available"
app:iconGravity="textStart"
app:iconPadding="16dp"
app:iconTint="#FFFFFF" />
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<!--<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <!--<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
@ -75,31 +130,6 @@
<include layout="@layout/content_main" /> <include layout="@layout/content_main" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="0dp"
app:contentInsetStart="0dp">
<Button
android:id="@+id/ok_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:padding="12dp"
android:text="@string/button_add"
android:textColor="#FFFFFF"
app:cornerRadius="24dp"
app:icon="@drawable/ic_event_available"
app:iconGravity="textStart"
app:iconPadding="16dp"
app:iconTint="#FFFFFF" />
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>--> </androidx.coordinatorlayout.widget.CoordinatorLayout>-->

View File

@ -7,9 +7,9 @@
tools:showIn="@layout/activity_main" tools:showIn="@layout/activity_main"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="64dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical" android:orientation="vertical">
android:layout_margin="16dp">
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_uri_input" android:id="@+id/layout_uri_input"
@ -17,11 +17,15 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
app:endIconCheckable="false" app:endIconCheckable="false"
app:endIconDrawable="@drawable/ic_backspace_black" app:endIconDrawable="@drawable/ic_backspace_black"
app:errorIconDrawable="@drawable/ic_backspace_black"
app:endIconMode="custom" app:endIconMode="custom"
app:errorIconDrawable="@drawable/ic_backspace_black"
app:helperText="@string/helper_add_link" app:helperText="@string/helper_add_link"
app:helperTextEnabled="true"> app:helperTextEnabled="true">
@ -42,148 +46,4 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>
<!--<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="32dp"
android:layout_marginBottom="64dp"
android:divider="@drawable/divider"
android:orientation="vertical"
android:showDividers="middle">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_uri_input"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:endIconCheckable="false"
app:endIconDrawable="@drawable/ic_backspace_black"
app:errorIconDrawable="@drawable/ic_backspace_black"
app:endIconMode="custom"
app:helperText="@string/helper_add_link"
app:helperTextEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_uri_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:cursorVisible="true"
android:hint="@string/hint_add_link"
android:inputType="textNoSuggestions"
android:singleLine="true"
android:textColorLink="@color/material_on_background_emphasis_high_type" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false"
android:hint="@string/hint_event_name"
android:inputType="textNoSuggestions"
android:singleLine="true"
android:textColorLink="@color/material_on_background_emphasis_high_type" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false"
android:hint="@string/hint_event_start"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false"
android:hint="@string/hint_event_end"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_event_location"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:endIconDrawable="@drawable/ic_add_location"
app:endIconMode="custom">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false"
android:hint="@string/hint_event_location"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_event_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:focusable="false"
android:cursorVisible="false"
android:hint="@string/hint_event_description"
android:inputType="textNoSuggestions|textMultiLine"
android:singleLine="false"
android:textColorLink="@color/material_on_background_emphasis_high_type" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>-->

View File

@ -1,25 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"> android:layout_margin="16dp">
<LinearLayout <LinearLayout
android:id="@+id/linear_layout" android:id="@+id/linear_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="32dp"
android:layout_marginBottom="64dp"
android:divider="@drawable/divider" android:divider="@drawable/divider"
android:orientation="vertical" android:orientation="vertical"
android:showDividers="middle"> android:showDividers="middle">
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -29,8 +24,8 @@
android:id="@+id/edit_text_event_name" android:id="@+id/edit_text_event_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false" android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_name" android:hint="@string/hint_event_name"
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions"
android:singleLine="true" android:singleLine="true"
@ -46,8 +41,8 @@
android:id="@+id/edit_text_event_start" android:id="@+id/edit_text_event_start"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false" android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_start" android:hint="@string/hint_event_start"
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions"
android:singleLine="true" /> android:singleLine="true" />
@ -62,8 +57,8 @@
android:id="@+id/edit_text_event_end" android:id="@+id/edit_text_event_end"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false" android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_end" android:hint="@string/hint_event_end"
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions"
android:singleLine="true" /> android:singleLine="true" />
@ -82,8 +77,8 @@
android:id="@+id/edit_text_event_location" android:id="@+id/edit_text_event_location"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false" android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_location" android:hint="@string/hint_event_location"
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions"
android:singleLine="true" /> android:singleLine="true" />
@ -99,8 +94,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:autoLink="web" android:autoLink="web"
android:focusable="false"
android:cursorVisible="false" android:cursorVisible="false"
android:focusable="false"
android:hint="@string/hint_event_description" android:hint="@string/hint_event_description"
android:inputType="textNoSuggestions|textMultiLine" android:inputType="textNoSuggestions|textMultiLine"
android:singleLine="false" android:singleLine="false"
@ -109,4 +104,4 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </com.google.android.material.card.MaterialCardView>