Skip to content

Commit

Permalink
Backend changes and search added
Browse files Browse the repository at this point in the history
  • Loading branch information
eagskunst committed Jul 29, 2018
1 parent 9f4956e commit b85293d
Show file tree
Hide file tree
Showing 36 changed files with 257 additions and 78 deletions.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,41 @@ See changelog on develop branch for not-official features.
2. Select File -> New -> Project from Version Control -> GitHub
3. Enter your github username and password.
4. Copy this repo's clone url.
5. Select the repository and hit clone.
5. Select the repository and hit clone.


# Changelog

**-27/7/2018:** Added the posibility to search articles. Added custom navigation view icons. Erased one es/PS4 link.

**-19/7/2018:** Finished (my) proper navigation between fragments. Added also an int[] to check NavigationView actual item when onBackPressed().

**-15/7/2018:** Fixed Exception caused by refreshLayout.setRefreshing(false);
Implemented a better navigation between fragments but still is unfinished.


**-14/7/2018:**
Added a drawer layout with a navigation view.

Changed MainActivity's all in one for a Fragment that can handle all categories of news.

Changed ParserMaker's use of variable Activity in order to avoid a NullException. Now use an interface.

Created Urls.json file for reading urls depending on language.

Added GSON library for Json reading.

Created Categories inside Models package.

Created LoadUrls for handling the reading of the Json file.

Created WebViewActivity.

Deleted icon in toolbar.xml layout. Now is added with toolbar.setIcon()

Changed harcoded strings and dimens.

**-11/7/2018:** Changed colors. Added app icon inside toolbar. Added a Floating Action Button for back to top compability.
**-2/7/2018:** Bugfixes for Locale and proper onBackPressed when paserMaker.isRunning = true. Change min. version for Android 4.1 Improvement of ParserMaker

**-27/6/2018:** First commit.
15 changes: 7 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".views.MainActivity"
android:launchMode="singleTask"
>
<activity
android:name=".views.MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".views.WebViewActivity"
android:parentActivityName=".views.MainActivity"
<activity
android:name=".views.WebViewActivity"
android:launchMode="singleTop"
>
android:parentActivityName=".views.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".views.MainActivity"
/>
android:value=".views.MainActivity" />
</activity>
</application>

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/assets/Urls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"http://feeds.feedburner.com/SCEEBlogES",
"https://puregaming.es/juegos-ps4/feed/",
"https://www.egamers.com/category/ps4/feed/",
"http://es.ign.com/ps4.xml",
"http://www.laps4.com/foro/external.php?type=RSS2&forumids=2"
"http://es.ign.com/ps4.xml"
],
"xboxO_urls":[
"https://puregaming.es/juegos-xbox-one/feed/",
Expand All @@ -33,7 +32,6 @@
{
"language": "en",
"all_urls": [
"https://www.gamespot.com/feeds/news/",
"https://www.vg247.com/feed/",
"https://www.eurogamer.net/?format=rss",
"https://kotaku.com/tag/gaming/rss",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import com.squareup.picasso.Picasso;


import java.util.ArrayList;
import java.util.List;

public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.NewsViewHolder> {
private final String TAG = "MainActivity";

private List<NewsModel> newsList;
private List<NewsModel> newsListCopy = new ArrayList<>();
private NewsViewHolder.OnItemClickListener onItemClickListener;

public NewsAdapter(List<NewsModel> newsList, NewsViewHolder.OnItemClickListener onItemClickListener) {
Expand Down Expand Up @@ -56,6 +58,26 @@ public int getItemCount() {
return newsList.size();
}

public List<NewsModel> getNewsListCopy() {
return newsListCopy;
}


public void filter(String text) {
newsList.clear();
if(text.isEmpty()){
newsList.addAll(newsListCopy);
} else{
text = text.toLowerCase();
for(NewsModel item: newsListCopy){
if(item.getTitle().toLowerCase().contains(text)){
newsList.add(item);
}
}
}
notifyDataSetChanged();
}


public static class NewsViewHolder extends RecyclerView.ViewHolder{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
Expand Down Expand Up @@ -46,16 +49,18 @@ public NewsListFragment() {
// Required empty public constructor
}


@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
public static NewsListFragment newInstance(String[] urls) {
Bundle args = new Bundle();
args.putStringArray("urls", urls);
NewsListFragment fragment = new NewsListFragment();
fragment.setArguments(args);
return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment

View view = inflater.inflate(R.layout.fragment_news_list,container,false);
String[] urls;
recyclerView = view.findViewById(R.id.recyclerview);
Expand All @@ -74,18 +79,25 @@ public void onClick(View view) {
ParserMaker.OnNewsFinishListener newsFinishListener = new ParserMaker.OnNewsFinishListener() {
@Override
public void onNewsFinish() {
refreshLayout.setRefreshing(false);
if(getActivity() != null){
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
refreshLayout.setRefreshing(false);
}
});
}
parserMaker.setRunning(false);
}
};

parserMaker = new ParserMaker(newsFinishListener,urls,
Toast.makeText(getActivity(), R.string.cant_get_articles, Toast.LENGTH_SHORT),
this.newsAdapter,this.newsList);

parserMaker.create();

refreshLayout.setRefreshing(true);
if(newsList.isEmpty()){
parserMaker.create();
refreshLayout.setRefreshing(true);
}
manageRefreshLayout(parserMaker);
return view;
}
Expand All @@ -97,6 +109,12 @@ public void onButtonPressed(Uri uri) {
}
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
setHasOptionsMenu(true);
super.onCreate(savedInstanceState);
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
Expand All @@ -123,19 +141,41 @@ public void onDestroy() {
}

@Override
public void onResume() {
super.onResume();
//parserMaker.setActivity(parserMaker.isRunning() ? getActivity():null);
public void onDestroyView() {
super.onDestroyView();
}

@Override
public void onPause() {
super.onPause();
//parserMaker.setActivity(parserMaker.isRunning() ? getActivity():null);
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.search_menu,menu);
SearchView searchView = (SearchView) menu.findItem(R.id.searchMenu).getActionView();

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
if(!parserMaker.isRunning()){
newsAdapter.filter(s);
return true;
}
else{
return false;
}
}

@Override
public boolean onQueryTextChange(String s) {
if(!parserMaker.isRunning()){
newsAdapter.filter(s);
return true;
}
else{
return false;
}
}
});

super.onCreateOptionsMenu(menu, inflater);
}

private void manageRecyclerView(boolean autoMeasure, boolean fixedSize) {
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
Expand Down Expand Up @@ -236,4 +276,5 @@ public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void onTaskCompleted(ArrayList<Article> list) {
orderListRecentFirst();
}
newsAdapter.notifyDataSetChanged();
newsAdapter.getNewsListCopy().addAll(newsList);
refreshingStatus();
}
}
Expand Down Expand Up @@ -141,13 +142,6 @@ public int compare(NewsModel newsModel, NewsModel t1) {

private void refreshingStatus(){
onNewsFinishListener.onNewsFinish();
/*activity.runOnUiThread(new Runnable() {
@Override
public void run() {
((SwipeRefreshLayout)activity.findViewById(R.id.refreshlayout)).setRefreshing(false);
running = false;
}
});*/
}

public void setRunning(boolean running) {
Expand Down
Loading

0 comments on commit b85293d

Please sign in to comment.