1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-06-26 13:34:52 +02:00

Added HashtagFragment

This commit is contained in:
vanitasvitae 2016-09-30 23:15:10 +02:00
parent 850f759cde
commit fec93a0660
6 changed files with 189 additions and 7 deletions

View file

@ -65,6 +65,7 @@ import com.github.dfa.diaspora_android.data.PodUserProfile;
import com.github.dfa.diaspora_android.fragment.BrowserFragment;
import com.github.dfa.diaspora_android.fragment.CustomFragment;
import com.github.dfa.diaspora_android.fragment.DiasporaStreamFragment;
import com.github.dfa.diaspora_android.fragment.HashtagListFragment;
import com.github.dfa.diaspora_android.fragment.TestFragment;
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
import com.github.dfa.diaspora_android.receiver.OpenExternalLinkReceiver;
@ -228,7 +229,7 @@ public class MainActivity extends AppCompatActivity
* Show DiasporaStreamFragment if necessary and load URL url
* @param url URL to load in the DiasporaStreamFragment
*/
protected void openDiasporaUrl(String url) {
public void openDiasporaUrl(String url) {
AppLog.v(this, "openDiasporaUrl()");
DiasporaStreamFragment streamFragment = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
showFragment(streamFragment);
@ -256,14 +257,17 @@ public class MainActivity extends AppCompatActivity
BrowserFragment bf = new BrowserFragment();
fm.beginTransaction().add(bf, fragmentTag).commit();
return bf;
case HashtagListFragment.TAG:
HashtagListFragment hlf = new HashtagListFragment();
fm.beginTransaction().add(hlf, fragmentTag).commit();
return hlf;
case TestFragment.TAG:
TestFragment tf = new TestFragment();
fm.beginTransaction().add(tf, fragmentTag).commit();
return tf;
default:
AppLog.e(this,"Invalid Fragment Tag: "+fragmentTag
+"\nAdd Fragments Tag to getFragment()'s switch case.");
return null;
TestFragment tf = new TestFragment();
fm.beginTransaction().add(tf, fragmentTag).commit();
return tf;
}
}
}
@ -780,7 +784,7 @@ public class MainActivity extends AppCompatActivity
//TODO: Replace with fragment
case R.id.nav_followed_tags: {
DiasporaStreamFragment stream = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
/*DiasporaStreamFragment stream = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getBlankUrl());
WebHelper.showFollowedTagsList(stream.getWebView(), app);
@ -788,6 +792,8 @@ public class MainActivity extends AppCompatActivity
} else {
snackbarNoInternet.show();
}
*/
showFragment(getFragment(HashtagListFragment.TAG));
}
break;

View file

@ -0,0 +1,125 @@
package com.github.dfa.diaspora_android.fragment;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
/**
* Fragment that shows a list of the Hashtags the user follows
* Created by vanitas on 29.09.16.
*/
public class HashtagListFragment extends CustomFragment {
public static final String TAG = "com.github.dfa.diaspora_android.HashtagListFragment";
protected RecyclerView followedTagsRecyclerView;
protected String[] followedTags;
protected App app;
protected DiasporaUrlHelper urls;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
AppLog.d(this, "onCreateView()");
return inflater.inflate(R.layout.hashtag_list__fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.followedTagsRecyclerView = (RecyclerView) view.findViewById(R.id.fragment_followed_tags__recycler_view);
this.app = (App) getActivity().getApplication();
this.urls = new DiasporaUrlHelper(app.getSettings());
followedTags = app.getPodUserProfile().getFollowedTags();
followedTagsRecyclerView.setHasFixedSize(true);
followedTagsRecyclerView.setNestedScrollingEnabled(false);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this.getContext());
followedTagsRecyclerView.setLayoutManager(layoutManager);
final FollowedTagsAdapter adapter = new FollowedTagsAdapter(followedTags, onHashtagClickListener);
followedTagsRecyclerView.setAdapter(adapter);
}
@Override
public String getFragmentTag() {
return TAG;
}
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override
public boolean onBackPressed() {
return false;
}
protected View.OnClickListener onHashtagClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
int itemPosition = followedTagsRecyclerView.getChildLayoutPosition(view);
if(itemPosition > -1 && itemPosition < followedTags.length) {
String tag = followedTags[itemPosition];
((MainActivity)getActivity()).openDiasporaUrl(urls.getSearchTagsUrl(tag));
}
}
};
public static class FollowedTagsAdapter extends RecyclerView.Adapter<FollowedTagsAdapter.ViewHolder> {
private String[] followedTagsList;
private View.OnClickListener itemClickListener;
public static class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView title;
public ViewHolder(View v) {
super(v);
title = (TextView) v.findViewById(R.id.recycler_view__list_item__text);
}
}
// Provide a suitable constructor (depends on the kind of dataset)
public FollowedTagsAdapter(String[] tags, View.OnClickListener itemClickListener) {
this.followedTagsList = tags;
this.itemClickListener = itemClickListener;
}
@Override
public FollowedTagsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.recycler_view__list_item, parent, false);
v.setOnClickListener(itemClickListener);
return new ViewHolder(v);
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.title.setText(followedTagsList[position]);
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return followedTagsList.length;
}
}
}

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/fragment_followed_tags__recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<!-- Offset -->
<android.support.v4.widget.Space
android:id="@+id/spacer"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_toolbar_height"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>

View file

@ -32,7 +32,7 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_gravity="bottom|end"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_behavior=".ui.BottomBarBehavior">

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider"/>
<TextView
android:id="@+id/recycler_view__list_item__text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider"/>
</LinearLayout>

View file

@ -7,6 +7,7 @@
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
<dimen name="bottom_toolbar_height">45dp</dimen>
<!-- Per the design guidelines, navigation drawers should be between 240dp and 320dp:
https://developer.android.com/design/patterns/navigation-drawer.html -->