package com.dowerx.quack.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import androidx.fragment.app.Fragment;

import com.dowerx.quack.R;
import com.dowerx.quack.service.PostService;

public class NewPostFragment extends Fragment {

    EditText content;

    public NewPostFragment() {
        // Required empty public constructor
    }

    public static NewPostFragment newInstance() {
        NewPostFragment fragment = new NewPostFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_new_post, container, false);
        content = view.findViewById(R.id.content);
        view.findViewById(R.id.send_post).setOnClickListener(this::send_post);
        return view;
    }

    public void send_post(View view) {
        PostService.NewPost task = new PostService.NewPost(this.getActivity());
        task.execute(content.getText().toString());
    }
}