Commit 352dcd08 authored by Varun Patil's avatar Varun Patil

Make webview fragment generic

parent 2e58bb49
......@@ -64,6 +64,16 @@ public class Constants {
public static final String CARD_TYPE_TITLE = "card_type_title";
public static final String CARD_TYPE_BODY_HEAD = "card_type_body_head";
/* Webview */
public static final String WV_TYPE = "webview_type";
public static final String WV_TYPE_ADD_EVENT = "add_event";
public static final String WV_TYPE_UPDATE_EVENT = "update_event";
public static final String WV_TYPE_UPDATE_BODY = "update_body";
public static final String WV_TYPE_ACHIEVEMENTS = "achievements";
public static final String WV_TYPE_URL = "url_type";
public static final String WV_ID = "id";
public static final String WV_URL = "url";
/* Map */
public static final double MAP_Xn = 19.133691, MAP_Yn = 72.916984, MAP_Zn = 4189, MAP_Zyn = 1655;
public static final double[] MAP_WEIGHTS_X = {-7.769917472065843, 159.26978694839946, 244.46989575495544, -6.003894110679995, -0.28864271213341297, 0.010398324019718075, 4.215508849724247, -0.6078830146963545, -7.0400449629241395};
......
......@@ -251,7 +251,8 @@ public class BodyFragment extends BackHandledFragment implements TransitionTarge
public void onClick(View v) {
WebViewFragment webViewFragment = new WebViewFragment();
Bundle bundle = new Bundle();
bundle.putString("bodyId", body.getBodyID());
bundle.putString(Constants.WV_TYPE, Constants.WV_TYPE_UPDATE_BODY);
bundle.putString(Constants.WV_ID, body.getBodyID());
webViewFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(webViewFragment);
}
......
......@@ -43,6 +43,7 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import app.insti.Constants;
import app.insti.R;
import app.insti.Utils;
import app.insti.activity.MainActivity;
......@@ -140,6 +141,11 @@ public class CalendarFragment extends BaseFragment {
CalendarDay day = ((MaterialCalendarView) view.findViewById(R.id.simpleCalendarView)).getSelectedDate();
String date = day.getYear() + "-" + day.getMonth() + "-" + day.getDay();
WebViewFragment webViewFragment = (new WebViewFragment()).withDate(date);
Bundle bundle = new Bundle();
bundle.putString(Constants.WV_TYPE, Constants.WV_TYPE_ADD_EVENT);
webViewFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(webViewFragment);
}
});
......
......@@ -357,7 +357,8 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg
fab.setOnClickListener(v -> {
WebViewFragment webViewFragment = new WebViewFragment();
Bundle bundle = new Bundle();
bundle.putString("id", event.getEventID());
bundle.putString(Constants.WV_TYPE, Constants.WV_TYPE_UPDATE_EVENT);
bundle.putString(Constants.WV_ID, event.getEventID());
webViewFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(webViewFragment);
});
......
......@@ -18,6 +18,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.List;
import app.insti.ActivityBuffer;
import app.insti.Constants;
import app.insti.R;
import app.insti.Utils;
import app.insti.activity.MainActivity;
......@@ -133,6 +134,7 @@ public class FeedFragment extends BaseFragment {
public void onClick(View v) {
WebViewFragment webViewFragment = new WebViewFragment();
Bundle bundle = new Bundle();
bundle.putString(Constants.WV_TYPE, Constants.WV_TYPE_ADD_EVENT);
webViewFragment.setArguments(bundle);
((MainActivity) getActivity()).updateFragment(webViewFragment);
}
......
......@@ -46,11 +46,58 @@ public class WebViewFragment extends BaseFragment {
// Required empty public constructor
}
private final String host = "insti.app";
public WebViewFragment withDate(String date) {
query += "&date=" + date;
return this;
}
private void setTitle(String title) {
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setTitle(title);
}
}
private String chooseUrl(Bundle args) {
setTitle("InstiApp");
// Construct basic URL
String url = "https://" + host;
// Check for type
if (!args.containsKey(Constants.WV_TYPE)) {
return url;
}
// Check for arguments
final String type = args.getString(Constants.WV_TYPE);
final String ID = args.getString(Constants.WV_ID);
switch (type) {
case Constants.WV_TYPE_ADD_EVENT:
url += "/add-event/";
setTitle("Add Event");
break;
case Constants.WV_TYPE_UPDATE_EVENT:
url += "/edit-event/" + ID;
setTitle("Update Event");
break;
case Constants.WV_TYPE_UPDATE_BODY:
url += "/edit-body/" + ID;
setTitle("Update Organization");
break;
case Constants.WV_TYPE_URL:
return args.getString(Constants.WV_URL);
}
return url + "?sandbox=true";
}
@Override
public void onStart() {
super.onStart();
......@@ -68,10 +115,6 @@ public class WebViewFragment extends BaseFragment {
progressDialog.setCancelable(false);
progressDialog.show();
String host = "insti.app";
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle(getArguments().containsKey("id") ? "Update Event" : "Add Event");
if (savedInstanceState == null) {
WebView webView = view.findViewById(R.id.add_event_webview);
webView.getSettings().setBuiltInZoomControls(true);
......@@ -93,17 +136,7 @@ public class WebViewFragment extends BaseFragment {
CookieSyncManager.getInstance().sync();
}
String url = "https://" + host + "/add-event?sandbox=true";
if (getArguments().containsKey("id")) {
url = "https://" + host + "/edit-event/" + getArguments().getString("id") + "?sandbox=true";
} else if (getArguments().containsKey("bodyId")) {
url = "https://" + host + "/edit-body/" + getArguments().getString("bodyId") + "?sandbox=true";
toolbar.setTitle("Update Organization");
}
url += query;
webView.loadUrl(url);
webView.loadUrl(chooseUrl(getArguments()) + query);
webView.setOnTouchListener(new View.OnTouchListener() {
float m_downX;
......
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