package adullact.publicrowdfunding.controller.project.add;
-import java.util.ArrayList;
-import java.util.Calendar;
-
-import adullact.publicrowdfunding.R;
-import adullact.publicrowdfunding.controller.adaptor.CarouselAdaptor;
-import adullact.publicrowdfunding.model.exception.NoAccountExistsInLocal;
-import adullact.publicrowdfunding.model.local.callback.HoldToDo;
-import adullact.publicrowdfunding.model.local.ressource.Account;
-import adullact.publicrowdfunding.model.local.ressource.Project;
-import adullact.publicrowdfunding.model.local.ressource.User;
-import adullact.publicrowdfunding.model.local.utilities.Utility;
-import adullact.publicrowdfunding.model.server.event.CreateEvent;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
-import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
-import com.google.android.gms.maps.model.LatLng;
-import com.touchmenotapps.carousel.simple.HorizontalCarouselLayout;
-import com.touchmenotapps.carousel.simple.HorizontalCarouselLayout.CarouselInterface;
-import com.touchmenotapps.carousel.simple.HorizontalCarouselStyle;
+import java.util.Calendar;
+
+import org.joda.time.DateTime;
+
+import adullact.publicrowdfunding.R;
+import adullact.publicrowdfunding.model.exception.NoAccountExistsInLocal;
+import adullact.publicrowdfunding.model.local.callback.HoldToDo;
+import adullact.publicrowdfunding.model.local.ressource.Account;
+import adullact.publicrowdfunding.model.local.ressource.User;
+import adullact.publicrowdfunding.model.local.utilities.Utility;
/**
* @author Ferrand and Nelaupe
private Context context;
- private int m_illustration;
-
- private addLocationProjectFragment _map;
-
- private User user;
-
private ImageView avatar;
- private HorizontalCarouselStyle mStyle;
- private HorizontalCarouselLayout mCarousel;
- private CarouselAdaptor mAdapter;
- private ArrayList<Integer> mData;
-
- private LinearLayout loading;
-
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
context = this.getActivity().getApplicationContext();
+ BreadCrumbView breadCrumb = (BreadCrumbView) view
+ .findViewById(R.id.breadcrumb);
+ breadCrumb.setPosition(1);
+
m_titre = (EditText) view.findViewById(R.id.titre);
m_Description = (EditText) view.findViewById(R.id.description);
m_dateFin = (DatePicker) view.findViewById(R.id.date_de_fin);
avatar = (ImageView) view.findViewById(R.id.avatar);
- mCarousel = (HorizontalCarouselLayout) view
- .findViewById(R.id.carousel_layout);
-
- loading = (LinearLayout) view.findViewById(R.id.loading);
-
- mCarousel.setOnCarouselViewChangedListener(new CarouselInterface() {
-
- @Override
- public void onItemChangedListener(View v, int position) {
- m_illustration = position;
- }
- });
-
m_valider.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- /*
- * Validation
- */
+ addProjectRequest();
+
}
});
}
String StrDay = "" + day;
- LatLng position = new LatLng(0, 0);
+ String endDate = Stryear + "-" + StrMonth + "-" + StrDay + " 00:00:00";
+
try {
- position = _map.getPosition();
- } catch (NullPointerException e) {
- e.printStackTrace();
+ DateTime endDateTime = Utility.stringToDateTime(endDate);
+ DateTime now = DateTime.now();
+ if (endDateTime.isBefore(now)) {
+ throw new Exception();
+ }
+ } catch (Exception e) {
+ Toast.makeText(context, "Date de fin invalide", Toast.LENGTH_SHORT)
+ .show();
+ return;
}
- new Project(titre, description, user.getResourceId(), somme,
- Utility.stringToDateTime(Stryear + "-" + StrMonth + "-"
- + StrDay + " 00:00:00"),
- Utility.stringToDateTime(Stryear + "-" + StrMonth + "-"
- + StrDay + " 00:00:00"), position, m_illustration,
- m_email.getText().toString(), m_website.getText().toString(),
- m_phone.getText().toString(), false)
- .serverCreate(new CreateEvent<Project>() {
- @Override
- public void errorResourceIdAlreadyUsed() {
-
- Toast.makeText(context, R.string.error,
- Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onCreate(Project resource) {
+ FragmentTransaction ft = getActivity().getSupportFragmentManager()
+ .beginTransaction().disallowAddToBackStack();
+ Fragment fragment = new addImageFragment();
+ Bundle args = new Bundle();
- Toast.makeText(context, R.string.error,
- Toast.LENGTH_SHORT).show();
- }
+ args.putString("title", titre);
+ args.putString("description", description);
+ args.putString("somme", somme);
+ args.putString("endDate", endDate);
- @Override
- public void errorAuthenticationRequired() {
- Toast.makeText(context, "Vous devez vous authentifier",
- Toast.LENGTH_SHORT).show();
-
- }
+ if (m_email.length() > 0) {
+ String email = m_email.getText().toString();
+ args.putString("email", email);
+ }
- @Override
- public void errorNetwork() {
- Toast.makeText(context, R.string.error,
- Toast.LENGTH_SHORT).show();
-
- }
+ if (m_phone.length() > 0) {
+ String phone = m_phone.getText().toString();
+ args.putString("phone", phone);
+ }
- @Override
- public void errorServer() {
- Toast.makeText(context, R.string.error,
- Toast.LENGTH_SHORT).show();
+ if (m_website.length() > 0) {
+ String website = m_website.getText().toString();
+ args.putString("website", website);
+ }
- }
- });
+ fragment.setArguments(args);
+ fragment.setHasOptionsMenu(true);
+ ft.replace(R.id.content_frame, fragment);
+ ft.commit();
}
}
- public void loadMaps() {
- try {
- FragmentManager fm = getActivity().getSupportFragmentManager();
- FragmentTransaction ft = fm.beginTransaction();
- Fragment fragment = new addLocationProjectFragment();
- ft.replace(R.id.mapView, fragment);
- ft.commit();
- _map = (addLocationProjectFragment) fragment;
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
public void loadContent() {
- new Thread(new Runnable() {
-
- @Override
- public void run() {
-
- try {
- Account compte = Account.getOwn();
- compte.getUser(new HoldToDo<User>() {
-
- @Override
- public void hold(User resource) {
-
- user = resource;
-
-
- m_user_pseudo.setText(resource.getPseudo());
- m_user_ville.setText(resource.getCity());
- if (resource.getGender().equals("0")) {
- avatar.setImageResource(R.drawable.male_user_icon);
- } else {
- avatar.setImageResource(R.drawable.female_user_icon);
- }
-
- }
+ try {
+ Account compte = Account.getOwn();
+ compte.getUser(new HoldToDo<User>() {
+
+ @Override
+ public void hold(User resource) {
+
+ m_user_pseudo.setText(resource.getPseudo());
+ m_user_ville.setText(resource.getCity());
+ if (resource.getGender().equals("0")) {
+ avatar.setImageResource(R.drawable.male_user_icon);
+ } else {
+ avatar.setImageResource(R.drawable.female_user_icon);
+ }
- });
- } catch (NoAccountExistsInLocal e) {
- e.printStackTrace();
}
- m_illustration = 0;
-
- mData = new ArrayList<Integer>();
- mData.add(R.drawable.ic_launcher);
- mData.add(R.drawable.roi);
- mData.add(R.drawable.basketball);
- mData.add(R.drawable.plante);
- mData.add(R.drawable.fete);
-
- mAdapter = new CarouselAdaptor(context);
- mAdapter.setData(mData);
- mStyle = new HorizontalCarouselStyle(context,
- HorizontalCarouselStyle.NO_STYLE);
- mCarousel.setStyle(mStyle);
- mCarousel.setAdapter(mAdapter);
-
- supprimerCalendarView();
- loading.setVisibility(View.GONE);
-
- }
- }).start();
+ });
+ } catch (NoAccountExistsInLocal e) {
+ e.printStackTrace();
+ }
- loadMaps();
+ supprimerCalendarView();
}
+
}
\ No newline at end of file