Commit 5451ff1f authored by Lennart Bader's avatar Lennart Bader
Browse files

New Header Files, added Events, new Layouts

parent 1b7878b1
......@@ -24,12 +24,11 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.github.amlcurran.showcaseview:library:5.4.3'
}
package de.mytfg.apps.vplan.activities;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentContainer;
import android.support.v7.app.AppCompatActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import java.util.Set;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.fragments.AboutFragment;
import de.mytfg.apps.vplan.fragments.AuthenticationFragment;
import de.mytfg.apps.vplan.fragments.FeedbackFragment;
import de.mytfg.apps.vplan.fragments.LinksFragment;
import de.mytfg.apps.vplan.fragments.NewsFragment;
import de.mytfg.apps.vplan.fragments.OfficeFragment;
import de.mytfg.apps.vplan.fragments.SettingsFragment;
import de.mytfg.apps.vplan.fragments.LoginFragment;
import de.mytfg.apps.vplan.fragments.PlanFragment;
import de.mytfg.apps.vplan.fragments.StartFragment;
import de.mytfg.apps.vplan.fragments.TfgFragment;
import de.mytfg.apps.vplan.fragments.VrrFragment;
import de.mytfg.apps.vplan.navigation.Navigation;
import de.mytfg.apps.vplan.toolbar.ToolbarManager;
......@@ -66,9 +62,9 @@ public class MainActivity extends AppCompatActivity {
switch (item.getItemId()) {
default:
return false;
case R.id.mainmenu_start:
case R.id.mainmenu_news:
navi.clear();
navi.navigate(new StartFragment(), R.id.fragment_container);
navi.navigate(new TfgFragment(), R.id.fragment_container);
return true;
case R.id.mainmenu_plan:
navi.clear();
......@@ -132,7 +128,7 @@ public class MainActivity extends AppCompatActivity {
Class c = Class.forName(fragName);
fragment = (AuthenticationFragment)c.newInstance();
} catch (Exception ex) {
fragment = new StartFragment();
fragment = new TfgFragment();
}
}
}
......
package de.mytfg.apps.vplan.adapters;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.objects.TfgEventsEntry;
import de.mytfg.apps.vplan.objects.TfgNewsEntry;
import de.mytfg.apps.vplan.tools.Settings;
public class EventsEntryHolder extends RecyclerView.ViewHolder {
private TextView title;
private TextView date;
private TextView day;
private TextView month;
private TextView year;
private TextView location;
private Context context;
private CardView cardView;
public EventsEntryHolder(View view) {
super(view);
context = view.getContext();
cardView = (CardView) view;
title = (TextView) view.findViewById(R.id.event_title);
//date = (TextView) view.findViewById(R.id.event_date);
day = (TextView) view.findViewById(R.id.event_day);
month = (TextView) view.findViewById(R.id.event_month);
year = (TextView) view.findViewById(R.id.event_year);
location = (TextView) view.findViewById(R.id.event_location);
}
public void update(TfgEventsEntry entry) {
//titleView.setText(baseObject.getName());
title.setText(entry.getTitle());
long ts = entry.getTimestamp();
day.setText(MyTFGApi.getDay(ts));
month.setText(MyTFGApi.getMonth(ts));
year.setText(MyTFGApi.getYear(ts));
String time = entry.getTime();
String loc = entry.getLocation();
if (time.length() > 0) {
loc += loc.length() > 0 ? ", " + time : time;
}
location.setText(loc);
if (loc.length() == 0) {
location.setVisibility(View.GONE);
} else {
location.setVisibility(View.VISIBLE);
}
}
public void setOnClickListener(CardView.OnClickListener listener) {
cardView.setOnClickListener(listener);
}
public CardView getCardView() {
return cardView;
}
}
......@@ -40,8 +40,10 @@ public class FragmentHolder extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
resId = getArguments().getInt("fraglayout");
View view = inflater.inflate(resId, container, false);;
Log.d("FH", "onCreateView");
if (logic != null) {
Log.d("FH", "Logic exists");
logic.init(getContext(), view, getArguments());
}
return view;
......
package de.mytfg.apps.vplan.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.UUID;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.objects.TfgEventsEntry;
import de.mytfg.apps.vplan.objects.TfgNewsEntry;
public class RecylcerEventsAdapter extends RecyclerView.Adapter<EventsEntryHolder> {
private Context context;
private ArrayList<TfgEventsEntry> elements = new ArrayList<>();
private String unique;
public RecylcerEventsAdapter(Context c) {
this.context = c;
unique = UUID.randomUUID().toString();
}
public void addItem(TfgEventsEntry item) {
elements.add(item);
}
public int getCount() {
return elements.size();
}
@Override
public EventsEntryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).
inflate(R.layout.cardview_eventsentry, null);
EventsEntryHolder eventsEntryHolder = new EventsEntryHolder(view);
return eventsEntryHolder;
}
@Override
public void onBindViewHolder(final EventsEntryHolder holder, final int position) {
holder.update(elements.get(position));
}
@Override
public int getItemCount() {
return elements.size();
}
public void clear() {
elements.clear();
}
}
......@@ -285,7 +285,7 @@ public class MyTFGApi {
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setReadTimeout(5000);
connection.setReadTimeout(8000);
connection.setConnectTimeout(10000);
connection.setRequestMethod("POST");
connection.setDoInput(true);
......@@ -369,4 +369,40 @@ public class MyTFGApi {
return "--";
}
}
public static String getDay(long timestamp) {
timestamp = timestamp * 1000;
try{
DateFormat sdf = new SimpleDateFormat("dd", Locale.GERMAN);
Date netDate = (new Date(timestamp));
return sdf.format(netDate);
}
catch(Exception ex){
return "--";
}
}
public static String getMonth(long timestamp) {
timestamp = timestamp * 1000;
try{
DateFormat sdf = new SimpleDateFormat("MMM", Locale.GERMAN);
Date netDate = (new Date(timestamp));
return sdf.format(netDate);
}
catch(Exception ex){
return "--";
}
}
public static String getYear(long timestamp) {
timestamp = timestamp * 1000;
try{
DateFormat sdf = new SimpleDateFormat("yyyy", Locale.GERMAN);
Date netDate = (new Date(timestamp));
return sdf.format(netDate);
}
catch(Exception ex){
return "--";
}
}
}
......@@ -31,6 +31,7 @@ public class AboutFragment extends AuthenticationFragment {
setHasOptionsMenu(true);
context.getToolbarManager()
.clear()
.showBottomScrim()
.setTitle(getString(R.string.menutitle_about))
.setExpandable(true, true);
......
package de.mytfg.apps.vplan.fragments;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.widget.CardView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.github.amlcurran.showcaseview.ShowcaseView;
import com.github.amlcurran.showcaseview.targets.ActionViewTarget;
import com.github.amlcurran.showcaseview.targets.ViewTarget;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.activities.MainActivity;
import de.mytfg.apps.vplan.adapters.RecylcerNewsAdapter;
import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.adapters.RecylcerVrrAdapter;
import de.mytfg.apps.vplan.api.SuccessCallback;
import de.mytfg.apps.vplan.objects.TfgNews;
import de.mytfg.apps.vplan.objects.TfgNewsEntry;
import de.mytfg.apps.vplan.objects.User;
import de.mytfg.apps.vplan.objects.Vplan;
import de.mytfg.apps.vplan.toolbar.ToolbarManager;
import de.mytfg.apps.vplan.tools.CustomViewTarget;
import de.mytfg.apps.vplan.objects.Vrr;
import de.mytfg.apps.vplan.objects.VrrEntry;
import de.mytfg.apps.vplan.tools.ItemOffsetDecoration;
import de.mytfg.apps.vplan.tools.ShowCaseManager;
public class StartFragment extends AuthenticationFragment {
public class NewsFragment extends AuthenticationFragment {
private View view;
private RecylcerNewsAdapter adapter;
private RecyclerView recyclerView;
private SwipeRefreshLayout swipeRefreshLayout;
public StartFragment() {
public NewsFragment() {
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false);
view = inflater.inflate(R.layout.fragment_news, container, false);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.base_refreshLayout);
MainActivity context = (MainActivity)this.getActivity();
recyclerView = (RecyclerView) view.findViewById(R.id.news_recylcerview);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 1);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.addItemDecoration(new ItemOffsetDecoration(getContext(), R.dimen.cardview_spacing));
setHasOptionsMenu(true);
context.getToolbarManager()
.clear()
.setTitle(getString(R.string.menutitle_home))
.showBottomScrim()
.setImage(R.drawable.news_header_s)
.setTitle(getString(R.string.menutitle_news))
.setExpandable(true, true);
MyTFGApi api = new MyTFGApi(context);
if (api.isLoggedIn()) {
User user = api.getUser();
TextView infotext = (TextView) view.findViewById(R.id.home_login_status);
String text = String.format(
getString(R.string.home_welcome_text),
user.getFirstname(),
user.getLastname(),
user.getLevel(),
user.getUsername(),
user.getGrade(),
api.getExpireString()
);
infotext.setText(Html.fromHtml(text));
}
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
displayNews();
}
});
this.displayNews();
ShowCaseManager scm = new ShowCaseManager(context);
View toolbar = ((MainActivity)getActivity()).getToolbarManager().getToolbar();
scm.createChain(this)
.add(new CustomViewTarget(toolbar, 50, 0, CustomViewTarget.Type.ABS_MID_L), R.string.sc_home_navi_title, R.string.sc_home_navi_text)
.showChain();
return view;
}
......@@ -96,26 +76,15 @@ public class StartFragment extends AuthenticationFragment {
super.onResume();
}
private void openUrl(String url) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
public void displayNews() {
final ProgressBar pb = (ProgressBar) view.findViewById(R.id.news_loading_bar);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview_news);
pb.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 1);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.addItemDecoration(new ItemOffsetDecoration(getContext(), R.dimen.cardview_spacing));
recyclerView = (RecyclerView) view.findViewById(R.id.news_recylcerview);
swipeRefreshLayout.setRefreshing(true);
final TfgNews news = new TfgNews(getContext());
news.load(new SuccessCallback() {
@Override
public void callback(boolean success) {
pb.setVisibility(View.GONE);
swipeRefreshLayout.setRefreshing(false);
if (success) {
adapter = new RecylcerNewsAdapter(getContext());
recyclerView.setAdapter(adapter);
......@@ -123,7 +92,6 @@ public class StartFragment extends AuthenticationFragment {
adapter.addItem(entry);
}
adapter.notifyDataSetChanged();
recyclerView.setVisibility(View.VISIBLE);
} else {
((MainActivity)getActivity()).getNavi().snackbar(getString(R.string.api_news_error));
}
......
......@@ -63,6 +63,8 @@ public class PlanFragment extends AuthenticationFragment {
.clear(false)
.setTitle(getString(R.string.menutitle_plan))
.clearMenu()
.setImage(R.drawable.vplan_header_s)
.showBottomScrim()
.setExpandable(true, true)
.setTabs(true)
.showFab()
......
package de.mytfg.apps.vplan.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
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.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.github.amlcurran.showcaseview.targets.Target;
import com.github.amlcurran.showcaseview.targets.ViewTarget;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.activities.MainActivity;
import de.mytfg.apps.vplan.adapters.FragmentHolder;
import de.mytfg.apps.vplan.adapters.ViewPagerAdapter;
import de.mytfg.apps.vplan.logic.EventsLogic;
import de.mytfg.apps.vplan.logic.NewsLogic;
import de.mytfg.apps.vplan.logic.PlanLogic;
import de.mytfg.apps.vplan.objects.TfgEvents;
import de.mytfg.apps.vplan.objects.TfgNews;
import de.mytfg.apps.vplan.objects.Vplan;
import de.mytfg.apps.vplan.toolbar.ToolbarManager;
import de.mytfg.apps.vplan.tools.CustomViewTarget;
import de.mytfg.apps.vplan.tools.ShowCaseManager;
public class TfgFragment extends AuthenticationFragment {
private View view;
private MainActivity context;
private NewsLogic newsLogic;
private TfgNews news;
private EventsLogic eventsLogic;
private TfgEvents events;
public TfgFragment() {
}
@Override
public boolean needsAuthentication() {
return true;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_tfg, container, false);
final MainActivity context = (MainActivity)this.getActivity();
this.context = context;
context.getToolbarManager()
.clear()
.setTitle(getString(R.string.menutitle_tfg))
.clearMenu()
.setImage(R.drawable.news_header_s)
.showBottomScrim()
.setExpandable(true, true)
.setTabs(true)
.setTabOutscroll(true);
return view;
}
@Override
public void onResume() {
super.onResume();
ViewPager viewPager = (ViewPager) view.findViewById(R.id.tfg_pager);
// Create Pager elements if not existent
if (newsLogic == null || eventsLogic == null) {
news = new TfgNews(context);
newsLogic = new NewsLogic(news, context);
events = new TfgEvents(context);
eventsLogic = new EventsLogic(events, context);
ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(this.getChildFragmentManager());
viewPagerAdapter.addFragment(
FragmentHolder.newInstance(
R.layout.fragment_news,
newsLogic
)
);
viewPagerAdapter.addFragment(
FragmentHolder.newInstance(
R.layout.fragment_events,
eventsLogic
)
);
viewPager.setAdapter(viewPagerAdapter);
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
switch (position) {
case 0:
context.getToolbarManager().setImage(R.drawable.news_header_s, true);
break;
case 1:
context.getToolbarManager().setImage(R.drawable.events_header_s, true);
break;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
TabLayout tabLayout = context.getToolbarManager().getTabs();
if (tabLayout != null) {
tabLayout.setupWithViewPager(viewPager);
}
}
}
package de.mytfg.apps.vplan.logic;
import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;