2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.fragments;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
2020-06-01 17:53:56 +02:00
|
|
|
import android.widget.LinearLayout;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.TextView;
|
2020-06-08 08:34:53 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.fragment.app.Fragment;
|
2021-02-11 11:23:35 +01:00
|
|
|
import org.gitnex.tea4j.models.Organization;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
2020-04-01 13:26:32 +02:00
|
|
|
import org.mian.gitnex.clients.PicassoService;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.FragmentOrganizationInfoBinding;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.Authorization;
|
|
|
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
2020-06-08 08:34:53 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class OrganizationInfoFragment extends Fragment {
|
|
|
|
|
|
|
|
private Context ctx = getContext();
|
|
|
|
private ProgressBar mProgressBar;
|
|
|
|
private static String orgNameF = "param1";
|
|
|
|
|
|
|
|
private String orgName;
|
|
|
|
private ImageView orgAvatar;
|
|
|
|
private TextView orgDescInfo;
|
|
|
|
private TextView orgWebsiteInfo;
|
|
|
|
private TextView orgLocationInfo;
|
2020-06-01 17:53:56 +02:00
|
|
|
private LinearLayout orgInfoLayout;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
private RepoInfoFragment.OnFragmentInteractionListener mListener;
|
|
|
|
|
|
|
|
public OrganizationInfoFragment() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static OrganizationInfoFragment newInstance(String param1) {
|
|
|
|
OrganizationInfoFragment fragment = new OrganizationInfoFragment();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putString(orgNameF, param1);
|
|
|
|
fragment.setArguments(args);
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
if (getArguments() != null) {
|
|
|
|
orgName = getArguments().getString(orgNameF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
FragmentOrganizationInfoBinding fragmentOrganizationInfoBinding = FragmentOrganizationInfoBinding.inflate(inflater, container, false);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
mProgressBar = fragmentOrganizationInfoBinding.progressBar;
|
|
|
|
orgAvatar = fragmentOrganizationInfoBinding.orgAvatar;
|
|
|
|
TextView orgNameInfo = fragmentOrganizationInfoBinding.orgNameInfo;
|
|
|
|
orgDescInfo = fragmentOrganizationInfoBinding.orgDescInfo;
|
|
|
|
orgWebsiteInfo = fragmentOrganizationInfoBinding.orgWebsiteInfo;
|
|
|
|
orgLocationInfo = fragmentOrganizationInfoBinding.orgLocationInfo;
|
|
|
|
orgInfoLayout = fragmentOrganizationInfoBinding.orgInfoLayout;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
orgNameInfo.setText(orgName);
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
getOrgInfo(Authorization.get(getContext()), orgName);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
return fragmentOrganizationInfoBinding.getRoot();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
private void getOrgInfo(String token, final String owner) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
Call<Organization> call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(getContext())
|
2019-06-03 23:25:05 +02:00
|
|
|
.getOrganization(token, owner);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<Organization>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<Organization> call, @NonNull retrofit2.Response<Organization> response) {
|
|
|
|
|
|
|
|
Organization orgInfo = response.body();
|
|
|
|
|
2020-06-01 17:53:56 +02:00
|
|
|
if (response.code() == 200) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-01 17:53:56 +02:00
|
|
|
orgInfoLayout.setVisibility(View.VISIBLE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-01 17:53:56 +02:00
|
|
|
assert orgInfo != null;
|
2020-06-08 08:34:53 +02:00
|
|
|
|
|
|
|
PicassoService.getInstance(ctx).get()
|
|
|
|
.load(orgInfo.getAvatar_url())
|
|
|
|
.placeholder(R.drawable.loader_animated)
|
|
|
|
.transform(new RoundedTransformation(8, 0))
|
|
|
|
.resize(230, 230)
|
|
|
|
.centerCrop().into(orgAvatar);
|
|
|
|
|
|
|
|
if(!orgInfo.getDescription().isEmpty()) {
|
|
|
|
orgDescInfo.setText(orgInfo.getDescription());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
orgDescInfo.setText(getString(R.string.noDataDescription));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!orgInfo.getWebsite().isEmpty()) {
|
|
|
|
orgWebsiteInfo.setText(orgInfo.getWebsite());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
orgWebsiteInfo.setText(getString(R.string.noDataWebsite));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!orgInfo.getLocation().isEmpty()) {
|
|
|
|
orgLocationInfo.setText(orgInfo.getLocation());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
orgLocationInfo.setText(getString(R.string.noDataLocation));
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-01 17:53:56 +02:00
|
|
|
mProgressBar.setVisibility(View.GONE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-06-01 17:53:56 +02:00
|
|
|
}
|
|
|
|
else if(response.code() == 404) {
|
|
|
|
|
|
|
|
mProgressBar.setVisibility(View.GONE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Log.e("onFailure", String.valueOf(response.code()));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Organization> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onButtonPressed(Uri uri) {
|
|
|
|
if (mListener != null) {
|
|
|
|
mListener.onFragmentInteraction(uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetach() {
|
|
|
|
super.onDetach();
|
|
|
|
mListener = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnFragmentInteractionListener {
|
|
|
|
void onFragmentInteraction(Uri uri);
|
|
|
|
}
|
|
|
|
}
|