Added repo watchers/subscribrs list
This commit is contained in:
		@@ -1,6 +1,5 @@
 | 
			
		||||
package org.mian.gitnex.activities;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import androidx.annotation.Nullable;
 | 
			
		||||
import androidx.appcompat.app.AppCompatActivity;
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,95 @@
 | 
			
		||||
package org.mian.gitnex.activities;
 | 
			
		||||
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import androidx.annotation.Nullable;
 | 
			
		||||
import androidx.appcompat.app.AppCompatActivity;
 | 
			
		||||
import androidx.lifecycle.Observer;
 | 
			
		||||
import androidx.lifecycle.ViewModelProvider;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.widget.GridView;
 | 
			
		||||
import android.widget.ImageView;
 | 
			
		||||
import android.widget.ProgressBar;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
import org.mian.gitnex.R;
 | 
			
		||||
import org.mian.gitnex.adapters.RepoWatchersAdapter;
 | 
			
		||||
import org.mian.gitnex.helpers.Authorization;
 | 
			
		||||
import org.mian.gitnex.models.UserInfo;
 | 
			
		||||
import org.mian.gitnex.util.TinyDB;
 | 
			
		||||
import org.mian.gitnex.viewmodels.RepoWatchersViewModel;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class RepoWatchersActivity extends AppCompatActivity {
 | 
			
		||||
 | 
			
		||||
    private TextView noDataWatchers;
 | 
			
		||||
    private View.OnClickListener onClickListener;
 | 
			
		||||
    private RepoWatchersAdapter adapter;
 | 
			
		||||
    private GridView mGridView;
 | 
			
		||||
    private ProgressBar mProgressBar;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        setContentView(R.layout.activity_repo_watchers);
 | 
			
		||||
 | 
			
		||||
        TinyDB tinyDb = new TinyDB(getApplicationContext());
 | 
			
		||||
        final String instanceUrl = tinyDb.getString("instanceUrl");
 | 
			
		||||
        final String loginUid = tinyDb.getString("loginUid");
 | 
			
		||||
        final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
 | 
			
		||||
 | 
			
		||||
        ImageView closeActivity = findViewById(R.id.close);
 | 
			
		||||
        TextView toolbarTitle = findViewById(R.id.toolbar_title);
 | 
			
		||||
        noDataWatchers = findViewById(R.id.noDataWatchers);
 | 
			
		||||
        mGridView = findViewById(R.id.gridView);
 | 
			
		||||
        mProgressBar = findViewById(R.id.progress_bar);
 | 
			
		||||
 | 
			
		||||
        String repoFullNameForWatchers = getIntent().getStringExtra("repoFullNameForWatchers");
 | 
			
		||||
        String[] parts = repoFullNameForWatchers.split("/");
 | 
			
		||||
        final String repoOwner = parts[0];
 | 
			
		||||
        final String repoName = parts[1];
 | 
			
		||||
 | 
			
		||||
        initCloseListener();
 | 
			
		||||
        closeActivity.setOnClickListener(onClickListener);
 | 
			
		||||
 | 
			
		||||
        toolbarTitle.setText(R.string.repoWatchersInMenu);
 | 
			
		||||
 | 
			
		||||
        fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void fetchDataAsync(String instanceUrl, String instanceToken, String repoOwner, String repoName) {
 | 
			
		||||
 | 
			
		||||
        RepoWatchersViewModel repoWatchersModel = new ViewModelProvider(this).get(RepoWatchersViewModel.class);
 | 
			
		||||
 | 
			
		||||
        repoWatchersModel.getRepoWatchers(instanceUrl, instanceToken, repoOwner, repoName).observe(this, new Observer<List<UserInfo>>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onChanged(@Nullable List<UserInfo> watchersListMain) {
 | 
			
		||||
                adapter = new RepoWatchersAdapter(getApplicationContext(), watchersListMain);
 | 
			
		||||
                if(adapter.getCount() > 0) {
 | 
			
		||||
                    mGridView.setAdapter(adapter);
 | 
			
		||||
                    noDataWatchers.setVisibility(View.GONE);
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    adapter.notifyDataSetChanged();
 | 
			
		||||
                    mGridView.setAdapter(adapter);
 | 
			
		||||
                    noDataWatchers.setVisibility(View.VISIBLE);
 | 
			
		||||
                }
 | 
			
		||||
                mProgressBar.setVisibility(View.GONE);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void initCloseListener() {
 | 
			
		||||
        onClickListener = new View.OnClickListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onClick(View view) {
 | 
			
		||||
                finish();
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -16,6 +16,7 @@ import com.amulyakhare.textdrawable.util.ColorGenerator;
 | 
			
		||||
import org.mian.gitnex.R;
 | 
			
		||||
import org.mian.gitnex.activities.RepoDetailActivity;
 | 
			
		||||
import org.mian.gitnex.activities.RepoStargazersActivity;
 | 
			
		||||
import org.mian.gitnex.activities.RepoWatchersActivity;
 | 
			
		||||
import org.mian.gitnex.models.UserRepositories;
 | 
			
		||||
import org.mian.gitnex.util.TinyDB;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
@@ -117,6 +118,9 @@ public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter.
 | 
			
		||||
 | 
			
		||||
                                case R.id.repoWatchers:
 | 
			
		||||
 | 
			
		||||
                                    Intent intentW = new Intent(context, RepoWatchersActivity.class);
 | 
			
		||||
                                    intentW.putExtra("repoFullNameForWatchers", fullNameMy.getText());
 | 
			
		||||
                                    context.startActivity(intentW);
 | 
			
		||||
                                    break;
 | 
			
		||||
 | 
			
		||||
                            }
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,91 @@
 | 
			
		||||
package org.mian.gitnex.adapters;
 | 
			
		||||
 | 
			
		||||
import android.annotation.SuppressLint;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.view.LayoutInflater;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.view.ViewGroup;
 | 
			
		||||
import android.widget.BaseAdapter;
 | 
			
		||||
import android.widget.ImageView;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
import com.squareup.picasso.Picasso;
 | 
			
		||||
import org.mian.gitnex.R;
 | 
			
		||||
import org.mian.gitnex.helpers.RoundedTransformation;
 | 
			
		||||
import org.mian.gitnex.models.UserInfo;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class RepoWatchersAdapter extends BaseAdapter {
 | 
			
		||||
 | 
			
		||||
    private List<UserInfo> watchersList;
 | 
			
		||||
    private Context mCtx;
 | 
			
		||||
 | 
			
		||||
    private class ViewHolder {
 | 
			
		||||
 | 
			
		||||
        private ImageView memberAvatar;
 | 
			
		||||
        private TextView memberName;
 | 
			
		||||
 | 
			
		||||
        ViewHolder(View v) {
 | 
			
		||||
            memberAvatar  = v.findViewById(R.id.memberAvatar);
 | 
			
		||||
            memberName  = v.findViewById(R.id.memberName);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RepoWatchersAdapter(Context mCtx, List<UserInfo> membersListMain) {
 | 
			
		||||
        this.mCtx = mCtx;
 | 
			
		||||
        this.watchersList = membersListMain;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getCount() {
 | 
			
		||||
        return watchersList.size();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Object getItem(int position) {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public long getItemId(int position) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SuppressLint("InflateParams")
 | 
			
		||||
    @Override
 | 
			
		||||
    public View getView(int position, View finalView, ViewGroup parent) {
 | 
			
		||||
 | 
			
		||||
        RepoWatchersAdapter.ViewHolder viewHolder;
 | 
			
		||||
 | 
			
		||||
        if (finalView == null) {
 | 
			
		||||
            finalView = LayoutInflater.from(mCtx).inflate(R.layout.repo_watchers_list, null);
 | 
			
		||||
            viewHolder = new RepoWatchersAdapter.ViewHolder(finalView);
 | 
			
		||||
            finalView.setTag(viewHolder);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            viewHolder = (RepoWatchersAdapter.ViewHolder) finalView.getTag();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        initData(viewHolder, position);
 | 
			
		||||
        return finalView;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void initData(RepoWatchersAdapter.ViewHolder viewHolder, int position) {
 | 
			
		||||
 | 
			
		||||
        UserInfo currentItem = watchersList.get(position);
 | 
			
		||||
        Picasso.get().load(currentItem.getAvatar()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(viewHolder.memberAvatar);
 | 
			
		||||
 | 
			
		||||
        if(!currentItem.getFullname().equals("")) {
 | 
			
		||||
            viewHolder.memberName.setText(currentItem.getFullname());
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            viewHolder.memberName.setText(currentItem.getLogin());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -20,6 +20,7 @@ import com.amulyakhare.textdrawable.util.ColorGenerator;
 | 
			
		||||
import org.mian.gitnex.R;
 | 
			
		||||
import org.mian.gitnex.activities.RepoDetailActivity;
 | 
			
		||||
import org.mian.gitnex.activities.RepoStargazersActivity;
 | 
			
		||||
import org.mian.gitnex.activities.RepoWatchersActivity;
 | 
			
		||||
import org.mian.gitnex.models.UserRepositories;
 | 
			
		||||
import org.mian.gitnex.util.TinyDB;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
@@ -119,6 +120,9 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
 | 
			
		||||
 | 
			
		||||
                                case R.id.repoWatchers:
 | 
			
		||||
 | 
			
		||||
                                    Intent intentW = new Intent(context, RepoWatchersActivity.class);
 | 
			
		||||
                                    intentW.putExtra("repoFullNameForWatchers", fullName.getText());
 | 
			
		||||
                                    context.startActivity(intentW);
 | 
			
		||||
                                    break;
 | 
			
		||||
 | 
			
		||||
                            }
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ import com.amulyakhare.textdrawable.util.ColorGenerator;
 | 
			
		||||
import org.mian.gitnex.R;
 | 
			
		||||
import org.mian.gitnex.activities.RepoDetailActivity;
 | 
			
		||||
import org.mian.gitnex.activities.RepoStargazersActivity;
 | 
			
		||||
import org.mian.gitnex.activities.RepoWatchersActivity;
 | 
			
		||||
import org.mian.gitnex.models.UserRepositories;
 | 
			
		||||
import org.mian.gitnex.util.TinyDB;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
@@ -117,6 +118,9 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
 | 
			
		||||
 | 
			
		||||
                                case R.id.repoWatchers:
 | 
			
		||||
 | 
			
		||||
                                    Intent intentW = new Intent(context, RepoWatchersActivity.class);
 | 
			
		||||
                                    intentW.putExtra("repoFullNameForWatchers", fullName.getText());
 | 
			
		||||
                                    context.startActivity(intentW);
 | 
			
		||||
                                    break;
 | 
			
		||||
 | 
			
		||||
                            }
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ import com.amulyakhare.textdrawable.util.ColorGenerator;
 | 
			
		||||
import org.mian.gitnex.R;
 | 
			
		||||
import org.mian.gitnex.activities.RepoDetailActivity;
 | 
			
		||||
import org.mian.gitnex.activities.RepoStargazersActivity;
 | 
			
		||||
import org.mian.gitnex.activities.RepoWatchersActivity;
 | 
			
		||||
import org.mian.gitnex.models.UserRepositories;
 | 
			
		||||
import org.mian.gitnex.util.TinyDB;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
@@ -117,6 +118,9 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
 | 
			
		||||
 | 
			
		||||
                                case R.id.repoWatchers:
 | 
			
		||||
 | 
			
		||||
                                    Intent intentW = new Intent(context, RepoWatchersActivity.class);
 | 
			
		||||
                                    intentW.putExtra("repoFullNameForWatchers", fullName.getText());
 | 
			
		||||
                                    context.startActivity(intentW);
 | 
			
		||||
                                    break;
 | 
			
		||||
 | 
			
		||||
                            }
 | 
			
		||||
 
 | 
			
		||||
@@ -207,4 +207,7 @@ public interface ApiInterface {
 | 
			
		||||
 | 
			
		||||
    @GET("repos/{owner}/{repo}/stargazers") // get all repo stars
 | 
			
		||||
    Call<List<UserInfo>> getRepoStargazers(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
 | 
			
		||||
 | 
			
		||||
    @GET("repos/{owner}/{repo}/subscribers") // get all repo watchers
 | 
			
		||||
    Call<List<UserInfo>> getRepoWatchers(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,60 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.models.UserInfo;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Author M M Arif
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class RepoWatchersViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    private static MutableLiveData<List<UserInfo>> watchersList;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<UserInfo>> getRepoWatchers(String instanceUrl, String token, String repoOwner, String repoName) {
 | 
			
		||||
 | 
			
		||||
        watchersList = new MutableLiveData<>();
 | 
			
		||||
        loadRepoWatchers(instanceUrl, token, repoOwner, repoName);
 | 
			
		||||
 | 
			
		||||
        return watchersList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadRepoWatchers(String instanceUrl, String token, String repoOwner, String repoName) {
 | 
			
		||||
 | 
			
		||||
        Call<List<UserInfo>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
                .getApiInterface()
 | 
			
		||||
                .getRepoWatchers(token, repoOwner, repoName);
 | 
			
		||||
 | 
			
		||||
        call.enqueue(new Callback<List<UserInfo>>() {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<UserInfo>> call, @NonNull Response<List<UserInfo>> response) {
 | 
			
		||||
 | 
			
		||||
                if(response.isSuccessful()) {
 | 
			
		||||
                    if(response.code() == 200) {
 | 
			
		||||
                        watchersList.postValue(response.body());
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onFailure(@NonNull Call<List<UserInfo>> call, Throwable t) {
 | 
			
		||||
                Log.i("onFailure", t.toString());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user