@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_date_choose);

    if (savedInstanceState != null) {
      year = savedInstanceState.getInt(YEAR);
      month = savedInstanceState.getInt(MONTH);
      day = savedInstanceState.getInt(DAY);
    } else {
      setTodayAsFullDate();
      UpgradeUtil.checkUpgrade(DateChooseActivity.this);
    }
    updateFullDate();

    writerView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            DateTime current = new DateTime(year, month, day, 0, 0);
            long dateSeconds = FullDateManager.getDateSeconds(current);
            Intent i = EditActivity.createIntent(DateChooseActivity.this, dateSeconds);
            startActivity(i);
          }
        });

    readerView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(DateChooseActivity.this, DiaryListActivity.class));
          }
        });

    dayChooser.setOnDayChooserClickListener(
        new DayChooser.OnDayChooserClickListener() {
          @Override
          public void onDayChoose(int chooseDay) {
            DayPickDialogFragment dayPickDialogFragment = new DayPickDialogFragment();
            Bundle bundle = new Bundle();
            bundle.putInt(DayPickDialogFragment.CHOOSE_DAY, chooseDay);
            bundle.putInt(DayPickDialogFragment.CHOOSE_MONTH, month);
            bundle.putInt(DayPickDialogFragment.CHOOSE_YEAR, year);
            dayPickDialogFragment.setArguments(bundle);
            dayPickDialogFragment.setOnDayChoosedListener(
                new DayPickDialogFragment.OnDayChoosedListener() {
                  @Override
                  public void onDayChoosed(DateTime chooseDate) {
                    setDate(chooseDate);
                    updateFullDate();
                  }
                });
            dayPickDialogFragment.show(getSupportFragmentManager(), null);
          }
        });
  }
Example #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    JianShiApplication.getInstance().getAppComponent().inject(MainActivity.this);

    userService
        .getJsonTest()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(
            new Subscriber<JsonDataResponse>() {
              @Override
              public void onCompleted() {
                Log.d("jaydebug", "onCompleted");
              }

              @Override
              public void onError(Throwable e) {
                Log.d("jaydebug", "onError");
              }

              @Override
              public void onNext(JsonDataResponse jsonDataResponse) {
                Log.d("jaydebug", "json data:" + jsonDataResponse.getData());
              }
            });

    Diary diary = DbUtil.getDiary(1);
    Preconditions.checkNotNull(diary);
    //    Log.d("jaydebug", "diary 1: " + diary.getTitle() + ", " + diary.getContent() + ", id " +
    // diary.getId() +
    //     ", device_id " + diary.getDeviceId() + ", createTime: " + diary.getCreatedTime() + ",
    // modified " + diary.getModifiedTime()
    //     + ", DELETE " + diary.getDeleted());
    userService
        .createDiary(
            diary.getTitle(), diary.getContent(), diary.getCreatedTime(), diary.getDeviceId())
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(
            new Subscriber<JsonDataResponse<Diary>>() {
              @Override
              public void onCompleted() {}

              @Override
              public void onError(Throwable e) {
                Log.d("jaydebug", "create diary Error");
              }

              @Override
              public void onNext(JsonDataResponse<Diary> diaryJsonDataResponse) {
                Log.d(
                    "jaydebug",
                    "create diary data: "
                        + diaryJsonDataResponse.getData().getTitle()
                        + ", "
                        + diaryJsonDataResponse.getData().getContent());
              }
            });

    setContentView(R.layout.activity_main);

    if (savedInstanceState != null) {
      year = savedInstanceState.getInt(YEAR);
      month = savedInstanceState.getInt(MONTH);
      day = savedInstanceState.getInt(DAY);
    } else {
      setTodayAsFullDate();
      UpgradeUtil.checkUpgrade(MainActivity.this);
    }
    updateFullDate();

    writerView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            DateTime current = new DateTime(year, month, day, 0, 0);
            long dateSeconds = FullDateManager.getDateSeconds(current);
            Intent i = EditActivity.createIntent(MainActivity.this, dateSeconds);
            startActivity(i);
          }
        });

    readerView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, DiaryListActivity.class));
          }
        });

    dayChooser.setOnDayChooserClickListener(
        new DayChooser.OnDayChooserClickListener() {
          @Override
          public void onDayChoose(int chooseDay) {
            DayPickDialogFragment dayPickDialogFragment = new DayPickDialogFragment();
            Bundle bundle = new Bundle();
            bundle.putInt(DayPickDialogFragment.CHOOSE_DAY, chooseDay);
            bundle.putInt(DayPickDialogFragment.CHOOSE_MONTH, month);
            bundle.putInt(DayPickDialogFragment.CHOOSE_YEAR, year);
            dayPickDialogFragment.setArguments(bundle);
            dayPickDialogFragment.setOnDayChoosedListener(
                new DayPickDialogFragment.OnDayChoosedListener() {
                  @Override
                  public void onDayChoosed(DateTime chooseDate) {
                    setDate(chooseDate);
                    updateFullDate();
                  }
                });
            dayPickDialogFragment.show(getSupportFragmentManager(), null);
          }
        });
  }