Beispiel #1
0
 public void initializeData() {
   mGetScenesNetworkHelper = new NetworkHelper(this);
   mCurrentFriend = (Friend) getIntent().getSerializableExtra(IntentExtraParams.FRIEND);
   mHistoryList = HistoryCache.getInstance(this).getHistoryList(mCurrentFriend);
   SceneCache sceneCache = SceneCache.getInstance(this);
   if (sceneCache.getList().size() > 0) {
     mSceneList = sceneCache.getList();
   } else {
     mGetScenesNetworkHelper.sendGetRequest(UrlParams.GET_SCENES_URL, mParams);
   }
   BackColorFactory backColorFactory = new BackColorFactory(this);
   mSceneHorizonAdapter = new SceneHorizonAdapter(this, mSceneList, backColorFactory);
   mHistoryAdapter = new HistoryAdapter(this, mCurrentFriend, mHistoryList);
 }
Beispiel #2
0
  private void setListener() {
    mBackImageView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(HistoryActivity.this, MenuActivity.class);
            intent.putExtra(
                IntentExtraParams.FRAGMENT_NAME, FragmentFactory.FragmentName.FriendBomb);
            startActivity(intent);
            finish();
          }
        });

    mBackTextView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(HistoryActivity.this, MenuActivity.class);
            intent.putExtra(
                IntentExtraParams.FRAGMENT_NAME, FragmentFactory.FragmentName.FriendBomb);
            startActivity(intent);
            finish();
          }
        });

    mSetBombTimeDialog.setDialogListener(
        new DialogListener() {
          @Override
          public void closeDialog() {
            mSetBombTimeDialog.dismiss();
          }
        });

    mSetBombTimeDialog.setAddHistoryListener(
        new AddHistoryListener() {
          @Override
          public void addHistory(int sceneId, String time) {
            LogUtil.d(TAG, "Time is: " + time);
            ClientUser clientUser = UserCache.getInstance().getClientUser();
            History history =
                new History(
                    SceneCache.getInstance(HistoryActivity.this).getScene(sceneId),
                    time,
                    0,
                    clientUser.getUserId(),
                    clientUser.getUserName());
            mHistoryList.add(history);
            mHistoryAdapter.notifyDataSetChanged();
            ConversationCache.getInstance()
                .updateConversation(
                    new Conversation(
                        mCurrentFriend.getUserId(),
                        String.format(getString(R.string.send_bomb_message), history.getTime())));
            mSetBombTimeDialog.dismiss();

            IMChattingHelper.getInstance(HistoryActivity.this).sendMessage(mCurrentFriend, history);
          }
        });

    mOnMessageReportCallback =
        new OnMessageReportCallback() {
          @Override
          public void onMessageReport(ECError error, ECMessage message) {}

          @Override
          public void onPushMessage() {
            mHistoryAdapter.notifyDataSetChanged();
          }
        };

    mGetScenesNetworkHelper.setUiDataListener(
        new UIDataListener<Bean>() {
          @Override
          public void onDataChanged(Bean data) {
            try {
              JSONObject result = new JSONObject(data.getResult());
              String sceneListStr = result.getString("scene.list");
              JSONArray sceneList = new JSONArray(sceneListStr);
              initializeSceneList();
              String sceneStr;
              for (int i = 0; i < sceneList.length(); i++) {
                sceneStr = sceneList.getString(i);
                JSONObject scene = new JSONObject(sceneStr);
                mSceneList.add(
                    new Scene(
                        scene.getInt("id"),
                        scene.getString("Name"),
                        scene.getString("Logo"),
                        scene.getString("Picture"),
                        scene.getString("Audio")));
              }
              mSceneHorizonAdapter.notifyDataSetChanged();
              SceneCache.getInstance(HistoryActivity.this).setList(mSceneList);
            } catch (JSONException e) {
              this.onErrorHappened(CodeParams.ERROR_SAVE_SESSION_TOKEN, e.toString());
            }
          }

          @Override
          public void onErrorHappened(int errorCode, String errorMessage) {}
        });

    mSceneListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mSetBombTimeDialog.setSceneInfo(mSceneList.get(position).getSceneId());
            mSetBombTimeDialog.show();
          }
        });
  }