コード例 #1
0
  public void onEventMainThread(UserPortraitUploadEvent event) {
    if (!isValidEvent(event)) {
      return;
    }

    if (event.isFailed()) {
      try {
        storeToCacheAndLaunchEvent(false, event, event.getUserId(), event.getPicturePath());
      } catch (Exception e) {
        notifyError(event);
      }
    } else {
      if (event.isRemote()) {
        store(true, event.getUserId(), event.getPicturePath());
      }

      User oldLoggedUser = SessionContext.getLoggedUser();

      if (event.getJSONObject() != null) {
        User user = new User(event.getJSONObject());
        if (oldLoggedUser != null && user.getId() == oldLoggedUser.getId()) {
          SessionContext.setLoggedUser(user);
        }
      }

      try {
        getListener().onUserPortraitUploaded(oldLoggedUser.getId());
      } catch (Exception e) {
        getListener().onUserPortraitUploadFailure(e);
      }
    }
  }
コード例 #2
0
  @Override
  protected void onUserAction(
      String userActionName, BaseUserPortraitInteractor interactor, Object... args) {

    try {
      if (UPLOAD_PORTRAIT.equals(userActionName)) {
        UserPortraitUploadInteractor userPortraitInteractor =
            (UserPortraitUploadInteractor) getInteractor(userActionName);
        String path = (String) args[0];
        if (_userId != 0) {
          userPortraitInteractor.upload(_userId, path);
        }
      } else {
        UserPortraitLoadInteractor userPortraitLoadInteractor =
            (UserPortraitLoadInteractor) getInteractor(userActionName);
        if (_portraitId != 0 && _uuid != null) {
          userPortraitLoadInteractor.load(_male, _portraitId, _uuid);
        } else {
          if (SessionContext.hasUserInfo() && _userId == 0) {
            userPortraitLoadInteractor.load(SessionContext.getLoggedUser().getId());
          } else {
            userPortraitLoadInteractor.load(_userId);
          }
        }
      }
    } catch (Exception e) {
      onUserPortraitLoadFailure(e);
    }
  }
コード例 #3
0
  private void sendRecords(Cache cache) {

    Long groupId = LiferayServerContext.getGroupId();
    List<DDLRecordCache> records = getLatestRecordsToSync(cache);

    DDLRecordService recordService =
        new DDLRecordService(SessionContext.createSessionFromCurrentSession());

    for (DDLRecordCache cachedRecord : records) {
      try {
        Record record = cachedRecord.getRecord();
        record.setCreatorUserId(SessionContext.getLoggedUser().getId());
        final JSONObject serviceContextAttributes = new JSONObject();
        serviceContextAttributes.put("userId", record.getCreatorUserId());
        serviceContextAttributes.put("scopeGroupId", groupId);
        JSONObjectWrapper serviceContextWrapper = new JSONObjectWrapper(serviceContextAttributes);
        JSONObject jsonContent = cachedRecord.getJSONContent();

        JSONObject jsonObject =
            saveOrUpdate(recordService, record, groupId, serviceContextWrapper, jsonContent);

        cachedRecord.setDirty(false);
        cachedRecord.setSyncDate(new Date());
        cache.set(cachedRecord);
      } catch (Exception e) {
        LiferayLogger.e("Error syncing a record", e);
      }
    }
  }
コード例 #4
0
  @Override
  protected View createScreenletView(Context context, AttributeSet attributes) {
    TypedArray typedArray =
        context
            .getTheme()
            .obtainStyledAttributes(attributes, R.styleable.UserPortraitScreenlet, 0, 0);

    _autoLoad = typedArray.getBoolean(R.styleable.UserPortraitScreenlet_autoLoad, true);
    _male = typedArray.getBoolean(R.styleable.UserPortraitScreenlet_male, true);
    _portraitId = typedArray.getInt(R.styleable.UserPortraitScreenlet_portraitId, 0);
    _uuid = typedArray.getString(R.styleable.UserPortraitScreenlet_uuid);
    _editable = typedArray.getBoolean(R.styleable.UserPortraitScreenlet_editable, false);

    int offlinePolicy =
        typedArray.getInt(
            R.styleable.UserPortraitScreenlet_offlinePolicy, OfflinePolicy.REMOTE_ONLY.ordinal());
    _offlinePolicy = OfflinePolicy.values()[offlinePolicy];

    _userId =
        castToLongOrUseDefault(typedArray.getString(R.styleable.UserPortraitScreenlet_userId), 0L);

    if (SessionContext.hasUserInfo() && _portraitId == 0 && _uuid == null && _userId == 0) {
      _userId = SessionContext.getLoggedUser().getId();
    }

    int layoutId =
        typedArray.getResourceId(R.styleable.UserPortraitScreenlet_layoutId, getDefaultLayoutId());

    typedArray.recycle();

    return LayoutInflater.from(context).inflate(layoutId, null);
  }
コード例 #5
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Log.v(TAG, "Going to store session");
    SessionContext.storeSession(CredentialsStoreBuilder.StorageType.SHARED_PREFERENCES);
    Log.v(TAG, "session stored");
    _user = SessionContext.getLoggedUser();

    View view = inflater.inflate(R.layout.fragment_home, container, false);
    welcomeHomeId = (TextView) view.findViewById(R.id.welcomeHomeId);
    travelDate = (Button) view.findViewById(R.id.travelDateId);
    fromLocation = (Spinner) view.findViewById(R.id.fromLocationId);
    toLocation = (Spinner) view.findViewById(R.id.toLocationId);
    findBusesButton = (Button) view.findViewById(R.id.findBusId);
    findBusesButton.setOnClickListener(this);
    travelDate.setOnClickListener(this);

    if (_user != null) {
      Log.v(TAG, "In Home user is " + _user.getEmail());
      welcomeHomeId.setText("Welcome " + _user.getFirstName());
    }

    ArrayAdapter<Locations> fromLocationsAdapter =
        new ArrayAdapter<Locations>(
            getActivity(), android.R.layout.simple_spinner_item, Locations.fromLocationsArray);
    fromLocationsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    fromLocation.setAdapter(fromLocationsAdapter);
    fromLocation.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.v(TAG, "From Drop down clicked ");
            Locations location = (Locations) parent.getItemAtPosition(position);
            Log.v(TAG, "Got location ");
            fromLocationId = location.getLocationId();
            Log.v(TAG, "Selected from location id is " + fromLocationId);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });

    ArrayAdapter<Locations> toLocationsAdapter =
        new ArrayAdapter<Locations>(
            getActivity(), android.R.layout.simple_spinner_item, Locations.toLocationsArray);
    toLocationsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    toLocation.setAdapter(toLocationsAdapter);
    toLocation.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Locations location = (Locations) parent.getItemAtPosition(position);
            toLocationId = location.getLocationId();
            Log.v(TAG, "Selected to location id is " + toLocationId);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });

    return view;
  }