当我将数据发布到服务器上时,我想在卡片查看项目上打两次勾,因为我想知道哪些数据已发布

时间:2019-06-13 13:02:52

标签: java android

我正在尝试发布我的CardView项目上的双勾号

private void postingIncoming(Date end, Date start, String number) {

    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String value = preferences.getString("user_id", "0");

    sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    final String newstartDate = sdf.format(start_time);
    final String newEndDate = sdf.format(end_time);


    OkHttpClient client = new OkHttpClient();

    MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");

    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("user_id", value);
        jsonObject.put("prospect_number", number);
        jsonObject.put("call_type", "incoming");
        jsonObject.put("talk_time", "30");
        jsonObject.put("start_datetime", newstartDate);
        jsonObject.put("end_datetime", newEndDate);


    } catch (JSONException e) {
        e.printStackTrace();
    }

    MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    RequestBody body = RequestBody.create(JSON, jsonObject.toString());

    Request request = new Request.Builder()
            .url("http://159.65.145.32/api/call/summary")
            .method("POST", body)
            .build();

    client.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
            e.printStackTrace();


            Realm.getDefaultInstance().executeTransaction(new Realm.Transaction() {
                @Override
                public void execute(Realm realm) {
                    Incoming_Detect k = realm.where(Incoming_Detect.class).findFirst();
                    k.setTest(false);
                }
            });

        }

        @Override
        public void onResponse(Call call, final Response response) throws IOException {


            if (!response.isSuccessful()) {

                Realm.getDefaultInstance().executeTransaction(new Realm.Transaction() {
                    @Override
                    public void execute(Realm realm) {
                        Incoming_Detect k = realm.where(Incoming_Detect.class).findFirst();
                        k.setTest(false);
                    }
                });
                throw new IOException("Unexpected code " + response);

            } else {
                String json = response.body().string();
                System.out.println("jsonUserId" + json);

//                    InCallLogAdapter.MyViewHolder.done.setVisibility(View.VISIBLE);


                try {

                    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
                    final SharedPreferences.Editor editor = preferences.edit();

                    JSONObject jsonobj = new JSONObject(json);
                    String str_value = jsonobj.getString("user_id");
                    editor.putString(str_value,"callerId").commit();
                    System.out.println("CallerId" + str_value);

                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }
        }
    });
}

////下面是我要在其中显示双击的适配器

public class InCallLogAdapter extends RealmRecyclerViewAdapter<Incoming_Detect, InCallLogAdapter.MyViewHolder> {

private Context context;
static MediaPlayer mp;

public InCallLogAdapter(Context context, RealmResults<Incoming_Detect> data ) {
    super(data, true);
    this.context = context;
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.custom_call_log_list_card, parent, false);

    return new MyViewHolder(itemView);
}


@Override
public void onBindViewHolder(@NonNull final InCallLogAdapter.MyViewHolder holder, final int position) {

    final Incoming_Detect object = getData().get(position);

    Incoming_Detect user = Realm.getDefaultInstance().where(Incoming_Detect.class).findFirst();

    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String value = preferences.getString("userName", "0");
    holder.iniby.setText("Initiated By :-    "+value);

    holder.num.setText("Phone Number :- "+object.getNum());
    holder.inDate.setText("Date :- "+object.getIncomingDate());


}


@Override
public long getItemId(int position) {
    return super.getItemId(position);
}

public static class MyViewHolder extends RecyclerView.ViewHolder {

    private TextView num,inDate,iniby;
    private ImageView playFile,pause;
    public static ImageView check,done;

    public MyViewHolder(View itemView) {
        super(itemView);

        num = itemView.findViewById(R.id.tv_number);
        inDate = itemView.findViewById(R.id.tv_date);
        playFile = itemView.findViewById(R.id.ic_play);
        pause = itemView.findViewById(R.id.ic_pause);
        check = itemView.findViewById(R.id.ic_check);
        done = itemView.findViewById(R.id.ic_done);
        iniby = (TextView) itemView.findViewById(R.id.tv_initiated);

        done.setVisibility(View.GONE);

        playFile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                pause.setVisibility(View.VISIBLE);
                playFile.setVisibility(View.INVISIBLE);

                 mp=new MediaPlayer();
                try{
                    //you can change the path, here path is external directory(e.g. sdcard) /Music/maine.mp3
                    mp.setDataSource(Environment.getExternalStorageDirectory().getPath()+"/Download/Bom Diggy Diggy.mp3");

                    mp.prepare();
                }catch(Exception e){e.printStackTrace();}

                mp.start();

            }
        });

        pause.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                pause.setVisibility(View.INVISIBLE);
                playFile.setVisibility(View.VISIBLE);
                mp.stop();

            }
        });
    }


}

我想知道哪个项目已发布在服务器上或剩下了

0 个答案:

没有答案