Commit c3ea8aa5 authored by Lennart Bader's avatar Lennart Bader
Browse files

Added Links, Menu for Partners and VRR.

parent 0e8f6c1d
......@@ -18,10 +18,12 @@ 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.LinksFragment;
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.VrrFragment;
import de.mytfg.apps.vplan.navigation.Navigation;
import de.mytfg.apps.vplan.toolbar.ToolbarManager;
import de.mytfg.apps.vplan.tools.Settings;
......@@ -74,14 +76,32 @@ public class MainActivity extends AppCompatActivity {
navi.clear();
navi.navigate(new PlanFragment(), R.id.fragment_container);
return true;
case R.id.mainmenu_vrr:
navi.clear();
navi.navigate(new VrrFragment(), R.id.fragment_container);
return true;
case R.id.mainmenu_account:
navi.clear();
navi.navigate(new SettingsFragment(), R.id.fragment_container);
return true;
case R.id.mainmenu_links:
navi.clear();
navi.navigate(new LinksFragment(), R.id.fragment_container);
return true;
case R.id.mainmenu_about:
navi.clear();
navi.navigate(new AboutFragment(), R.id.fragment_container);
return true;
// SUBMENU "PARTNERS"
case R.id.mainmenu_partners:
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.submenu_partners);
return true;
case R.id.submenu_partners_back:
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.navigation_menu);
return true;
}
}
});
......
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.TfgNewsEntry;
import de.mytfg.apps.vplan.objects.VrrEntry;
public class RecylcerVrrAdapter extends RecyclerView.Adapter<VrrEntryHolder> {
private Context context;
private ArrayList<VrrEntry> elements = new ArrayList<>();
private String unique;
public RecylcerVrrAdapter(Context c) {
this.context = c;
unique = UUID.randomUUID().toString();
}
public void addItem(VrrEntry item) {
elements.add(item);
}
public int getCount() {
return elements.size();
}
@Override
public VrrEntryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).
inflate(R.layout.cardview_vrrentry, null);
VrrEntryHolder vrrEntryHolder = new VrrEntryHolder(view);
return vrrEntryHolder;
}
@Override
public void onBindViewHolder(final VrrEntryHolder holder, final int position) {
holder.update(elements.get(position));
}
@Override
public int getItemCount() {
return elements.size();
}
public void clear() {
elements.clear();
}
}
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.view.View;
import android.widget.TextView;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.objects.TfgNewsEntry;
import de.mytfg.apps.vplan.objects.VrrEntry;
import de.mytfg.apps.vplan.tools.Settings;
public class VrrEntryHolder extends RecyclerView.ViewHolder {
private TextView line;
private TextView direction;
private TextView arrival;
private Context context;
private CardView cardView;
public VrrEntryHolder(View view) {
super(view);
context = view.getContext();
cardView = (CardView) view;
line = (TextView) view.findViewById(R.id.vrr_entry_line);
direction = (TextView) view.findViewById(R.id.vrr_dir);
arrival = (TextView) view.findViewById(R.id.vrr_time);
}
public void update(VrrEntry entry) {
line.setText(entry.getLine());
direction.setText(entry.getDirection());
arrival.setText(entry.getArrival());
}
public void setOnClickListener(CardView.OnClickListener listener) {
cardView.setOnClickListener(listener);
}
public CardView getCardView() {
return cardView;
}
}
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.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.activities.MainActivity;
public class LinksFragment extends Fragment {
private final String mytfgUrl = "https://mytfg.de";
private final String moodleUrl = "https://tfgym-duesseldorf.lms.schulon.org/";
private final String tfgUrl = "http://tfg-duesseldorf.de";
public LinksFragment() {
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_links, container, false);
MainActivity context = (MainActivity)this.getActivity();
setHasOptionsMenu(true);
context.getToolbarManager()
.clear()
.setTitle(getString(R.string.menutitle_links))
.setExpandable(true, true);
CardView mytfg = (CardView) view.findViewById(R.id.link_mytfg);
mytfg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(mytfgUrl));
startActivity(i);
}
});
final CardView moodle = (CardView) view.findViewById(R.id.link_moodle);
moodle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(moodleUrl));
startActivity(i);
}
});
CardView tfg = (CardView) view.findViewById(R.id.link_tfg_web);
tfg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(tfgUrl));
startActivity(i);
}
});
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
super.onCreateOptionsMenu(menu, inflater);
}
}
package de.mytfg.apps.vplan.fragments;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
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.ProgressBar;
import android.widget.TextView;
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.adapters.RecylcerVrrAdapter;
import de.mytfg.apps.vplan.api.MyTFGApi;
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.Vrr;
import de.mytfg.apps.vplan.objects.VrrEntry;
import de.mytfg.apps.vplan.tools.CustomViewTarget;
import de.mytfg.apps.vplan.tools.ItemOffsetDecoration;
import de.mytfg.apps.vplan.tools.ShowCaseManager;
public class VrrFragment extends Fragment {
private View view;
private RecylcerVrrAdapter adapter;
private RecyclerView recyclerView;
private SwipeRefreshLayout swipeRefreshLayout;
public VrrFragment() {
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_vrr, container, false);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.base_refreshLayout);
MainActivity context = (MainActivity)this.getActivity();
recyclerView = (RecyclerView) view.findViewById(R.id.vrr_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()
.setImage(R.mipmap.vrr_header_s)
.setTitle(getString(R.string.menutitle_vrr))
.setExpandable(true, true);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
displayVrr();
}
});
this.displayVrr();
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onResume() {
super.onResume();
}
public void displayVrr() {
recyclerView = (RecyclerView) view.findViewById(R.id.vrr_recylcerview);
swipeRefreshLayout.setRefreshing(true);
final Vrr vrr = new Vrr(getContext());
vrr.load(new SuccessCallback() {
@Override
public void callback(boolean success) {
swipeRefreshLayout.setRefreshing(false);
if (success) {
adapter = new RecylcerVrrAdapter(getContext());
recyclerView.setAdapter(adapter);
for (VrrEntry entry : vrr.getEntries()) {
adapter.addItem(entry);
}
adapter.notifyDataSetChanged();
} else {
((MainActivity)getActivity()).getNavi().snackbar(getString(R.string.api_vrr_error));
}
}
}, true);
}
}
......@@ -24,7 +24,6 @@ public class TfgNews extends MytfgObject {
private List<TfgNewsEntry> entries = new LinkedList<>();
private boolean loaded = false;
private long timestamp;
// 3 Minutes
private final long timeout = 60 * 60 * 1000; // 60 minutes
public TfgNews(Context context) {
......
package de.mytfg.apps.vplan.objects;
import android.content.Context;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.LinkedList;
import java.util.List;
import de.mytfg.apps.vplan.api.ApiCallback;
import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.api.SuccessCallback;
/**
* Manages VRR Entries returned by MyTFG
*/
public class Vrr extends MytfgObject {
private Context context;
private List<VrrEntry> entries = new LinkedList<>();
public Vrr(Context context) {
this.context = context;
}
public void load(SuccessCallback callback) {
this.load(callback, false);
}
public void load(final SuccessCallback callback, boolean clearCache) {
// Always request fresh data
MyTFGApi api = new MyTFGApi(context);
api.call("api_vrr_get", new ApiCallback() {
@Override
public void callback(JSONObject result, int responseCode) {
Log.d("RESP", "" + responseCode);
if (responseCode == 200) {
if (parse(result)) {
callback.callback(true);
} else {
callback.callback(false);
}
} else {
callback.callback(false);
}
}
});
}
private boolean parse(JSONObject result) {
this.entries = new LinkedList<>();
try {
JSONObject vrr = result.getJSONObject("vrr");
JSONArray entries = vrr.getJSONArray("preformatted");
for (int i = 0; i < entries.length(); ++i) {
VrrEntry entry = new VrrEntry();
entry.load(entries.getJSONArray(i));
this.entries.add(entry);
}
} catch (JSONException ex) {
ex.printStackTrace();
return false;
}
return true;
}
public List<VrrEntry> getEntries() {
return entries;
}
}
package de.mytfg.apps.vplan.objects;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import de.mytfg.apps.vplan.api.SuccessCallback;
/**
* Represents a VRR Entry
*/
public class VrrEntry extends MytfgObject {
private String line;
private String direction;
private String arrival;
/**
* Do not use this method. Use the load method and pass a JSON Object.
* @param callback Always called with false
*/
@Override
public void load(SuccessCallback callback) {
callback.callback(false);
}
public boolean load(JSONArray data) {
if (data == null) {
return false;
}
try {
line = data.getString(0);
direction = data.getString(1);
arrival = data.getString(2);
} catch (JSONException ex) {
return false;
}
return true;
}
public String getLine() {
return line;
}
public String getDirection() {
return direction;
}
public String getArrival() {
return arrival;
}
}
......@@ -77,6 +77,7 @@ public class ToolbarManager {
if (hideFab) {
this.hideFab();
}
this.setImage(R.mipmap.front);
this.clearMenu();
this.setTabs(false);
this.setTabOutscroll(false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment